fjcaetano / NSStringMask

NSStringMask allows you to apply masks or formats to NSStrings using NSRegularExpression to input your format.
http://fjcaetano.github.io/NSStringMask/
MIT License
241 stars 36 forks source link

Strange behavior with formatting #16

Closed Incorporalis closed 7 years ago

Incorporalis commented 7 years ago

format: ([a-zA-Z]{2})([0-9]{2}) ([a-zA-Z0-9]{4})

if we enter only one letter in beginning and digits after it and then we enter second letter - it is placed in beginning, after the first one: A11 -> A11(B) -> AB11 the same behavior with digits: AB1C -> AB1C(2) -> AB12 C if we enter only one letter and only one digit - it becomes more interesting A1 -> A1(B) -> AB1(C) -> AB1C(2) -> AB12 C

*string(input)

fjcaetano commented 7 years ago

Indeed. There seems to be an issue with validCharactersForString:. It will try to return the minimum for each group and concatenates them, so when you type A->1->1, it prints as "A_11", but that method will strip the underscores so it becomes "A11" which is then formatted.

I'm thinking that perhaps it should return the current concatenated string if it can't match the whole content of the group repetition (2 from ([a-zA-Z){2} in your case)

It's also worrisome that the tests are passing despite of this. Perhaps some of them need to be rewritten or improved