2
0
mirror of https://github.com/tenrok/BBob.git synced 2026-06-11 18:02:26 +03:00

fix(parser): infinity loop problem when escape [\b] (#31)

With enableEscapeTags: true, when trying to write [b]test[\b] page is crashed.
Fixes #23
This commit is contained in:
Nikolay Kostyurin
2019-06-30 11:15:10 +02:00
committed by GitHub
parent 3d5c1f19d5
commit b4cf27127f
2 changed files with 34 additions and 16 deletions
+16 -6
View File
@@ -11,6 +11,7 @@ const TYPE = {
};
const tokenize = input => (createLexer(input).tokenize());
const tokenizeEscape = input => (createLexer(input, { enableEscapeTags: true }).tokenize());
describe('lexer', () => {
const expectOutput = (output, tokens) => {
@@ -289,11 +290,9 @@ describe('lexer', () => {
});
test('escaped tag', () => {
const tokenizeEscape = input => (createLexer(input, {
enableEscapeTags: true
}).tokenize());
const input = '\\[b\\]test\\[';
const tokens = tokenizeEscape(input);
const output = [
[TYPE.WORD, '[', '0', '0'],
[TYPE.WORD, 'b', '0', '0'],
@@ -306,9 +305,6 @@ describe('lexer', () => {
});
test('escaped tag and escaped backslash', () => {
const tokenizeEscape = input => (createLexer(input, {
enableEscapeTags: true
}).tokenize());
const input = '\\\\\\[b\\\\\\]test\\\\\\[/b\\\\\\]';
const tokens = tokenizeEscape(input);
const output = [
@@ -328,6 +324,20 @@ describe('lexer', () => {
expectOutput(output, tokens);
});
test('bad closed tag with escaped backslash', () => {
const input = `[b]test[\\b]`;
const tokens = tokenizeEscape(input);
const output = [
[TYPE.TAG, 'b', '0', '3'],
[TYPE.WORD, 'test', '0', '7'],
[TYPE.WORD, '[', '0', '8'],
[TYPE.WORD, '\\', '0', '9'],
[TYPE.WORD, 'b]', '0', '11'],
];
expectOutput(output, tokens);
});
describe('html', () => {
const tokenizeHTML = input => createLexer(input, { openTag: '<', closeTag: '>' }).tokenize();