Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

fix issue #14, break out of regex loop if match length is 0 #15

Merged
merged 1 commit into from

2 participants

@johnkpaul

This was a mistake in my implementation of the match extraction algorithm. I've added a new testcase and fixed the issue.

@jonmagic jonmagic merged commit 8dc32ee into jonmagic:master
@jonmagic
Owner

Merged and pushed to production, but noticed this when I tested in production: http://cl.ly/3i133s1Y3Y0L01341S0Y

Probably shouldn't have a match group if it returns undefined. I can look at this tomorrow if you don't get a chance.

Thanks for the great PR, was so surprised to see it an hour or two after the bug came in :)

@johnkpaul

:) no problem! I happened to be on github a few minutes after you first commented on the bug, and I knew it was a problem with code that I just wrote.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
3  application.js
@@ -138,6 +138,9 @@
index: index,
length: length
});
+ if (length + index === 0) {
+ break;
+ }
value = value.substr(length + index);
}
return result;
View
1  scripts/application.coffee
@@ -104,6 +104,7 @@ class Results
index = execution.index
length = execution[0].length
result.push({index:index,length:length})
+ break if length+index == 0
value = value.substr(length+index)
result
View
1  spec/ResultsSpec.coffee
@@ -8,6 +8,7 @@ describe 'Results', ->
subjects = [
{'regex': 'a', 'test_strings': [{'string': 'a'}], 'output': '<span>a</span>'}
+ {'regex': '(issues)?', 'test_strings': [{'string': 'issues'}], 'output': '<span>issues</span>'}
{'regex': 'a$', 'test_strings': [{'string': 'asdfja'}], 'output': 'asdfj<span>a</span>'}
{'regex': '"$', 'test_strings': [{'string': '"hello"'}], 'output': '"hello<span>"</span>'}
{'regex': 'a(.*)c', 'test_strings': [{'string': 'abcdd', 'matches': ['b']}], 'output': '<span>abc</span>dd'}
View
8 spec/ResultsSpec.js
@@ -18,6 +18,14 @@
],
'output': '<span>a</span>'
}, {
+ 'regex': '(issues)?',
+ 'test_strings': [
+ {
+ 'string': 'issues'
+ }
+ ],
+ 'output': '<span>issues</span>'
+ }, {
'regex': 'a$',
'test_strings': [
{
Something went wrong with that request. Please try again.