Skip to content

Commit

Permalink
Make << in comment text parse correctly (#326)
Browse files Browse the repository at this point in the history
Inside comments two consecutive less-than characters (`<<`) parsed
wrongly as `<!`, due to what was probably a typo.  This fixes that.

Added regression test.

Fixes #325.
  • Loading branch information
anko committed Oct 1, 2020
1 parent 37227a3 commit 9c683e1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/parse5/lib/tokenizer/index.js
Expand Up @@ -1468,7 +1468,7 @@ class Tokenizer {
this.currentToken.data += '!';
this.state = COMMENT_LESS_THAN_SIGN_BANG_STATE;
} else if (cp === $.LESS_THAN_SIGN) {
this.currentToken.data += '!';
this.currentToken.data += '<';
} else {
this._reconsumeInState(COMMENT_STATE);
}
Expand Down
9 changes: 9 additions & 0 deletions packages/parse5/test/tokenizer.test.js
@@ -1,5 +1,7 @@
'use strict';

const assert = require('assert');
const parse5 = require('../lib');
const path = require('path');
const Tokenizer = require('../lib/tokenizer');
const Mixin = require('../lib/utils/mixin');
Expand All @@ -26,3 +28,10 @@ generateTokenizationTests(
return { tokenizer, getNextToken: () => tokenizer.getNextToken() };
}
);

exports['Regression - `<<` in comment parses correctly (GH-325)'] = {
test() {
const document = parse5.parse('<!--<<-->');
assert.equal(document.childNodes[0].data, '<<');
}
};

0 comments on commit 9c683e1

Please sign in to comment.