mirror of
https://github.com/tenrok/BBob.git
synced 2026-06-20 20:00:33 +03:00
fix: treat contextFreeTags case insensitively (#230)
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@bbob/parser": minor
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: treat contextFreeTags case insensitively
|
||||||
@@ -63,7 +63,9 @@ function createLexer(buffer, options = {}) {
|
|||||||
const openTag = options.openTag || OPEN_BRAKET;
|
const openTag = options.openTag || OPEN_BRAKET;
|
||||||
const closeTag = options.closeTag || CLOSE_BRAKET;
|
const closeTag = options.closeTag || CLOSE_BRAKET;
|
||||||
const escapeTags = !!options.enableEscapeTags;
|
const escapeTags = !!options.enableEscapeTags;
|
||||||
const contextFreeTags = options.contextFreeTags || [];
|
const contextFreeTags = (options.contextFreeTags || [])
|
||||||
|
.filter(Boolean)
|
||||||
|
.map((tag) => tag.toLowerCase());
|
||||||
const onToken = options.onToken || (() => {
|
const onToken = options.onToken || (() => {
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -92,7 +94,7 @@ function createLexer(buffer, options = {}) {
|
|||||||
contextFreeTag = '';
|
contextFreeTag = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (contextFreeTag === '' && contextFreeTags.includes(name)) {
|
if (contextFreeTag === '' && contextFreeTags.includes(name.toLowerCase())) {
|
||||||
contextFreeTag = name;
|
contextFreeTag = name;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -482,6 +482,24 @@ describe('lexer', () => {
|
|||||||
expect(tokens).toBeMantchOutput(output);
|
expect(tokens).toBeMantchOutput(output);
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('context free tag case insensitive [CODE]', () => {
|
||||||
|
const input = '[CODE] [b]some string[/b][/CODE]'
|
||||||
|
const tokens = tokenizeContextFreeTags(input, ['code']);
|
||||||
|
const output = [
|
||||||
|
[TYPE.TAG, 'CODE', 0, 0],
|
||||||
|
[TYPE.SPACE, ' ', 0, 0],
|
||||||
|
[TYPE.WORD, '[', 0, 0],
|
||||||
|
[TYPE.WORD, 'b]some', 0, 0],
|
||||||
|
[TYPE.SPACE, ' ', 0, 0],
|
||||||
|
[TYPE.WORD, 'string', 0, 0],
|
||||||
|
[TYPE.WORD, '[', 0, 0],
|
||||||
|
[TYPE.WORD, '/b]', 0, 0],
|
||||||
|
[TYPE.TAG, '/CODE', 0, 0],
|
||||||
|
]
|
||||||
|
|
||||||
|
expect(tokens).toBeMantchOutput(output);
|
||||||
|
})
|
||||||
|
|
||||||
test('bad closed tag with escaped backslash', () => {
|
test('bad closed tag with escaped backslash', () => {
|
||||||
const input = `[b]test[\\b]`;
|
const input = `[b]test[\\b]`;
|
||||||
const tokens = tokenizeEscape(input);
|
const tokens = tokenizeEscape(input);
|
||||||
|
|||||||
Reference in New Issue
Block a user