Permalink
Browse files

Fix: error thrown if continue(x, y) points after the end of the rule set

  • Loading branch information...
1 parent 979586f commit f2764a455e6b5205a3c7458ade66a05364a87e0e @pierrec committed Nov 23, 2012
Showing with 24 additions and 1 deletion.
  1. +4 −1 src/methods_ruleset.js
  2. +20 −0 test/rules-properties-methods-test.js
@@ -365,10 +365,13 @@ Atok.prototype._resolveRules = function (name) {
var rule = rules[i]
// Zero length rules
+
if ( rule.length === 0
&& (n === 1
|| (
- rules[ i + 1 + rule.continue ].length === 0
+ // continue may point to the end of the list
+ i + 1 + rule.continue < n
+ && rules[ i + 1 + rule.continue ].length === 0
// continueOnFail may point to the end of the list
&& i + 1 + rule.continueOnFail < n
&& rules[ i + 1 + rule.continueOnFail ].length === 0
@@ -476,6 +476,26 @@ describe('Tokenizer Properties Methods', function () {
})
})
+ describe('with an index pointing to the end of the rule set', function () {
+ var p = new Tokenizer(options)
+ it('should complete', function (done) {
+ p.continue(0)
+ p.addRule(1, 'consume')
+ p.write('a')
+ done()
+ })
+ })
+
+ describe('with an index on failure pointing to the end of the rule set', function () {
+ var p = new Tokenizer(options)
+ it('should complete', function (done) {
+ p.continue(-1, 0)
+ p.addRule('a', 'consume')
+ p.write('b')
+ done()
+ })
+ })
+
describe('with an invalid positive index', function () {
var p = new Tokenizer(options)
it('should throw on saveRuleSet()', function (done) {

0 comments on commit f2764a4

Please sign in to comment.