I work on improving the validation of form configurations that are saved in a python flask app. The form config comes in via an API in json.
A user can save a regex pattern for their form field to have additional validation.
Since I also wanted to prevent per default the submission of anything like an url in normal text fields (like First name, last name, etc.) I added a marshmallow regex pattern validation for all text fields: ^((?!\:\/\/).)*$
I also wanted a matching regex pattern on the frontend, where the form config is rendered into an actual html form. This is done by a small petite-vue app that provides the html templates for form fields and automatically adds the pattern from the json config file to the html.
I noticed:
Seems the backward slashes \ are a problem for json.
The slashes seem to be an issue here as well.
I already found out I can:
But now I'm stuck on deciding which potential solution is the more robust choice, and which of the two apps is the place to implement it.
So I need help deciding:
I found the answer to my question.
tldr;
The pattern is not right. You don't need to escape the "/" or the ":".
It should be: ^((?!://).)*$
Long version
In the app flow, the pattern gets saved via python in a json file (ie. it uses json_dumps() and already gets encoded). In my test case I just copy/pasted the pattern into the json file, resulting in not valid json. When escaping the \ manually, I either got an error on "invalid identity escape" or the pattern wouldn't match.