jaridmargolin / formatter.js

Format html inputs to match a specified pattern
http://firstopinion.github.io/formatter.js
2.48k stars 235 forks source link

Bug fix pattern suffix chars #36

Closed pedrocatre closed 10 years ago

pedrocatre commented 10 years ago

While using the plugin I noticed that when I have a pattern that has suffix chars and no pattern after them the library throws an error:

TypeError: Cannot read property 'index' of undefined at Object.pattern.parse (/Users/.../Desktop/.../formatter.js/src/pattern.js:61:29)

For example I might have a pattern for a a VAT number that looks like this: CHE- . . _ MWST

where the underscores are digits, so the pattern using formatter.js would be:

'pattern': 'CHE-{{999}}.{{999}}.{{999}} MWST'

which would throw an error when I open the page in a browser: 'Cannot read property 'index' of undefined' in line 61 of the formatter.js/src/pattern.js file. The only way this works is if I added a pattern after the ' MWST' suffix chars. Something like this: CHE-{{999}}.{{999}}.{{999}} MWST{{*}}

but I don't want to do that because it will add an extra character to the end of the input (at the very least a space character) and then the input would not pass validation. I added a test so you can see a similar case fail and then I applied a fix.

Thank you for your time and for this awesome library :)

jaridmargolin commented 10 years ago

Thank you for the PR. Apologies for the delayed response. This bug appears to have been fixed here: ff4d23b91a7e0d35ab59f4a66dd8719a1b5082e3