From d882ee8e0896b4d18b1bcf0ad9c2fd6de9fafe8f Mon Sep 17 00:00:00 2001 From: Jeff Avallone Date: Mon, 22 Dec 2014 15:18:49 -0500 Subject: [PATCH] Adding check that charset range is in correct order --- spec/parser/javascript/charset_range_spec.js | 7 +++++++ src/js/parser/javascript/charset_range.js | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/spec/parser/javascript/charset_range_spec.js b/spec/parser/javascript/charset_range_spec.js index 40420df..329524e 100644 --- a/spec/parser/javascript/charset_range_spec.js +++ b/spec/parser/javascript/charset_range_spec.js @@ -17,6 +17,13 @@ describe('parser/javascript/charset_range.js', function() { })); }); + it('throws an exception when the range is out of order', function() { + var parser = new javascript.Parser('z-a'); + expect(() => { + parser.__consume__charset_range(); + }).toThrow('Range out of order in character class: z-a'); + }); + describe('#_render', function() { beforeEach(function() { diff --git a/src/js/parser/javascript/charset_range.js b/src/js/parser/javascript/charset_range.js index 2b69d1b..cbc0dd2 100644 --- a/src/js/parser/javascript/charset_range.js +++ b/src/js/parser/javascript/charset_range.js @@ -26,5 +26,9 @@ export default { setup() { this.first = this.properties.first; this.last = this.properties.last; + + if (this.first.ordinal > this.last.ordinal) { + throw `Range out of order in character class: ${this.textValue}`; + } } };