User tests: Successful: Unsuccessful:
I simply put
new RegExp(" ... ")
around the email validation RegEx.
Reason : At least one very famous JS minifier which is in widespread use does stumble over this complex pattern, especially because they have problem recognizing them as such in the first place.
The simple 'wrap' makes it clearly and surely possible to identify the RegEx as such.
The Minifier I tested the most with and draw my conclusion from is JShrink from tedious ( https://github.com/tedious/JShrink ).
Pull Request for Issue # .
Status | New | ⇒ | Pending |
Category | ⇒ | JavaScript |
Go to patch-1 branch (#30275): https://github.com/Lab5-Switzerland/joomla-cms/blob/patch-1/media/system/js/validate-uncompressed.js
Edit the file with changes from this PR and submit.
Please remove the double quotes you've used. This changes it to a constructor object and the regex will not work.
See example:
const str = 'test@hotmail.com';
const regex1 = new RegExp("/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/");
const regex2 = new RegExp(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/);
console.log(regex1.test(str));
// expected output: true
console.log(regex2.test(str));
// expected output: true
Both expext true, however the constructor will return false
Both expext true, however the constructor will return false
it because the slash, not the double quotes:
const regex1 = new RegExp("^[a-z]*") // Correct
const regex2 = /^[a-z]*/ // Correct
const regex3 = new RegExp("/^[a-z]*/") // Wrong
As the only thing this PR does is to add the quotes removing them is the same as closing this PR ??
As the only thing this PR does is to add the quotes removing them is the same as closing this PR ??
very close , it still will have new RegExp( ... )
:)
well, I did not had such issue with minifier, for me it just a "cosmetic change" with new bugs :)
@Lab5-Switzerland one more problem with your changes, if you still want to use a double quote then you need to make sure that all back slash are escaped properly https://stackoverflow.com/a/37582643/1000711
Title |
|
Will close here for now and not accept this change into the 3.10-dev branch. when there are still issues please check with J4 and do a fresh pr agsinst it.
Status | Pending | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2022-06-12 17:56:46 |
Closed_By | ⇒ | zero-24 | |
Labels |
Added:
?
?
|
Please merge #30275 & #30276 into one pull request. Thanks.