RKEnumerator hits infinite loop on zero-length matches
Status: Beta
Brought to you by:
jengelhart
Given the pattern: ^.*$ (i.e. match entire line)
RKEnumerator seems to enter an infinite loop once it hits an "empty" line of input, i.e. a valid match which has zero length. I've not checked the code, but I rather suspect that it's failing to detect a zero length in the range of a match, and is thus starting the next search from the same location, and so on.
The fix would presumably be to check if a match's length is zero, and in that situation simply increment the start-location of the next search.
If I've made a mistake (or even if you can just confirm it), please let me know.
Logged In: YES
user_id=662514
Originator: NO
I just want to confirm this - and it's not just RKEnumerator. Seems to happen on at least NSString's stringByMatching:replace:withReferenceString, and probably everything else.
For example...
[@"!@#$Test string" stringByMatching:@"^[^A-Z]*" replace:RKReplaceAll withReferenceString:@""]
gives:
"Test string"
However,
[@"Test string" stringByMatching:@"^[^A-Z]*" replace:RKReplaceAll withReferenceString:@""]
Will freeze up forever.
See http://michael.tyson.id.au/RKFreezeTest.zip for a test project - Run it, press 'Run' and all is well; remove the four non-alpha chars from the test string, hit run again, and the app freezes.
Nasty stuff.