Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into feat/typescript-sup…
Browse files Browse the repository at this point in the history
…port
  • Loading branch information
JiLiZART committed Apr 20, 2024
2 parents 72e1926 + 05246b2 commit db9c64a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/dry-peas-develop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@bbob/parser": minor
---

fix: treat contextFreeTags case insensitively
6 changes: 4 additions & 2 deletions packages/bbob-parser/src/lexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ export function createLexer(buffer: string, options: LexerOptions = {}): LexerTo
const openTag = options.openTag || OPEN_BRAKET;
const closeTag = options.closeTag || CLOSE_BRAKET;
const escapeTags = !!options.enableEscapeTags;
const contextFreeTags = options.contextFreeTags || [];
const contextFreeTags = (options.contextFreeTags || [])
.filter(Boolean)
.map((tag) => tag.toLowerCase());
const onToken = options.onToken || (() => {
});

Expand Down Expand Up @@ -73,7 +75,7 @@ export function createLexer(buffer: string, options: LexerOptions = {}): LexerTo
contextFreeTag = '';
}

if (contextFreeTag === '' && contextFreeTags.includes(name)) {
if (contextFreeTag === '' && contextFreeTags.includes(name.toLowerCase())) {
contextFreeTag = name;
}
};
Expand Down
18 changes: 18 additions & 0 deletions packages/bbob-parser/test/lexer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,24 @@ describe('lexer', () => {
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', () => {
const input = `[b]test[\\b]`;
const tokens = tokenizeEscape(input);
Expand Down

0 comments on commit db9c64a

Please sign in to comment.