victorjonsson / jQuery-Form-Validator

[DISCONTINUED] jQuery plugin that makes it easy to validate user input while keeping your HTML markup clean from javascript code.
971 stars 475 forks source link

Invalid Range in Character Class in FireFox #538

Open BZinser opened 7 years ago

BZinser commented 7 years ago

When attempting to load html5 and date for the validator in FireFox ESR 31.2.0, the following stack dump is generated:

SyntaxError: invalid range in character class Stack:

  1. $.split@INTERNAL_URL/jQuery-Form-Validator-2.3.49/form-validator/jquery.form-validator.js:1091:7
  2. $.formUtils<.loadModules/loadModuleScripts@INTERNAL_URL/jQuery-Form-Validator-2.3.49/form-validator/jquery.form-validator.js:975:15
  3. $.formUtils<.loadModules/findScriptPathAndLoadModules@INTERNAL_URL/jQuery-Form-Validator-2.3.49/form-validator/jquery.form-validator.js:1055:13
  4. $.formUtils<.loadModules@INTERNAL_URL/jQuery-Form-Validator-2.3.49/form-validator/jquery.form-validator.js:1061:13
  5. $.validate@INTERNAL_URL/jQuery-Form-Validator-2.3.49/form-validator/jquery.form-validator.js:1235:7
  6. CUSTOM_FUNCTION:220:5 <--- this is where the validator is setup

Line 1091 is:

    var pattern = '[,|\-'+(allowSpaceAsDelimiter ? '\\s':'')+']\\s*',
      regex = new RegExp(pattern, 'g');

To fix the issue, I had to change it to (moved the dash to the end):

    var pattern = '[,|'+(allowSpaceAsDelimiter ? '\\s-':'')+']\\s*',
      regex = new RegExp(pattern, 'g');
victorjonsson commented 7 years ago

You have not moved the dashed to the end, the regex will only look for the dash in case allowSpaceAsDelimiter is set to true.

Could you please try if this works for you, and I'll add it to the code. '[,|'+(allowSpaceAsDelimiter ? '\\s':'')+'-]\\s*'

BZinser commented 7 years ago

Well, I was close ;)

I moved it to the actual end as you suggested and it worked in Chrome, Firefox and IE.