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}`; + } } };