2
0
mirror of https://github.com/tenrok/BBob.git synced 2026-06-08 17:22:26 +03:00

chore: v2.5.1 (#21)

* fix(parser): fix issue with escaping backslashes when enableEscapeTags is set (#20)

there is a bug in the lexer where when enableEscapeTags is set, backslashes
are not always escaped (ie. \\[b] is treated as an escaped tag, rather than a
literal backslash, and then a tag).

* chore: v2.5.1
This commit is contained in:
Nikolay Kostyurin
2019-06-18 09:56:21 +02:00
committed by GitHub
parent 3b46fbe23c
commit c4a88e5036
19 changed files with 151 additions and 20 deletions
+16
View File
@@ -3,6 +3,22 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
<a name="2.5.1"></a>
## [2.5.1](https://github.com/JiLiZART/bbob/compare/v2.4.1...v2.5.1) (2019-06-18)
### Bug Fixes
* **parser:** fix issue with escaping backslashes when enableEscapeTags is set ([#20](https://github.com/JiLiZART/bbob/issues/20)) ([8a9e930](https://github.com/JiLiZART/bbob/commit/8a9e930))
### Features
* **parse:** allow tags to be escaped with backslash ([#17](https://github.com/JiLiZART/bbob/issues/17)) ([c4f78c1](https://github.com/JiLiZART/bbob/commit/c4f78c1))
<a name="2.5.0"></a>
# [2.5.0](https://github.com/JiLiZART/bbob/compare/v2.4.1...v2.5.0) (2019-06-17)
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@bbob/parser",
"version": "2.5.0",
"version": "2.5.1",
"description": "Just parses BBcode to AST array. Part of @bbob bbcode parser",
"keywords": [
"bbcode",
+5 -1
View File
@@ -53,7 +53,7 @@ function createLexer(buffer, options = {}) {
const RESERVED_CHARS = [closeTag, openTag, QUOTEMARK, BACKSLASH, SPACE, TAB, EQ, N, EM];
const NOT_CHAR_TOKENS = [
...(options.enableEscapeTags ? [BACKSLASH] : []),
openTag, SPACE, TAB, N, BACKSLASH,
openTag, SPACE, TAB, N,
];
const WHITESPACES = [SPACE, TAB];
const SPECIAL_CHARS = [EQ, SPACE, TAB];
@@ -163,6 +163,10 @@ function createLexer(buffer, options = {}) {
bufferGrabber.skip(); // skip the \ without emitting anything
bufferGrabber.skip(); // skip past the [ or ] as well
emitToken(createToken(TYPE_WORD, nextChar, row, col));
} else if (options.enableEscapeTags && currChar === BACKSLASH && nextChar === BACKSLASH) {
bufferGrabber.skip(); // skip the first \ without emitting anything
bufferGrabber.skip(); // skip past the second \ and emit it
emitToken(createToken(TYPE_WORD, nextChar, row, col));
} else if (currChar === openTag) {
bufferGrabber.skip(); // skip openTag
+23
View File
@@ -305,6 +305,29 @@ describe('lexer', () => {
expectOutput(output, tokens);
});
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 = [
[TYPE.WORD, '\\', '0', '0'],
[TYPE.WORD, '[', '0', '0'],
[TYPE.WORD, 'b', '0', '0'],
[TYPE.WORD, '\\', '0', '0'],
[TYPE.WORD, ']', '0', '0'],
[TYPE.WORD, 'test', '0', '0'],
[TYPE.WORD, '\\', '0', '0'],
[TYPE.WORD, '[', '0', '0'],
[TYPE.WORD, '/b', '0', '0'],
[TYPE.WORD, '\\', '0', '0'],
[TYPE.WORD, ']', '0', '0'],
];
expectOutput(output, tokens);
});
describe('html', () => {
const tokenizeHTML = input => createLexer(input, { openTag: '<', closeTag: '>' }).tokenize();
+21 -1
View File
@@ -184,7 +184,7 @@ describe('Parser', () => {
]);
});
test('parse escaped tags tags', () => {
test('parse escaped tags', () => {
const ast = parse('\\[b\\]test\\[/b\\]', {
enableEscapeTags: true
});
@@ -199,5 +199,25 @@ describe('Parser', () => {
']',
]);
});
test('parse escaped tags and escaped backslash', () => {
const ast = parse('\\\\\\[b\\\\\\]test\\\\\\[/b\\\\\\]', {
enableEscapeTags: true
});
expectOutput(ast, [
'\\',
'[',
'b',
'\\',
']',
'test',
'\\',
'[',
'/b',
'\\',
']',
]);
});
});
});