guillaumepotier / Parsley.js

Validate your forms, frontend, without writing a single line of javascript
http://parsleyjs.org
MIT License
9.05k stars 1.32k forks source link

Issue in data-parsley-pattern when using unicode escape character 'u'. #1373

Open choppercoder opened 1 month ago

choppercoder commented 1 month ago

What kind of issue is this? (put 'x' between the square brackets)

Suppose I have a data object with regex in it, that is being fetched from an api, in the form- data = {regex : "/^[\p{L} .’_-]+$/u"}

If I assign data-parsley-pattern = data.regex, parsley.js transforms it into a format that always results to false where converted= /^\/^[\p{L} .’-]+$\/u$/ If I directly assign data.regex= /^[\p{L} .’-]+$/u then it works fine. I have tried to converted the stringified regex to object before assigning it, but nothing seems to work. the regex is always changed into something that gives the validation result as false even if value is correct.

The code I used to convert stringified regex to regex object is given here-

const data = { regex : "/^[\p{L} .’_-]+$/u" }; const [, regex, flags] = data.regex.match(/^\/(.)\/([a-z])$/); const pattern = new RegExp(regex, flags); console.log(pattern.test('check')); //this results to true