Skip to content

Commit

Permalink
fix: dont variable-ize escaped sequences (#458)
Browse files Browse the repository at this point in the history
* fix: dont variable-ize escaped sequences

* chore: oops
  • Loading branch information
kellyjosephprice authored Jul 20, 2023
1 parent f720e06 commit f8e8de7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
6 changes: 6 additions & 0 deletions __tests__/codeMirror.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ describe('variable substitution', () => {
'APIKEY NAME'
);
});

it('should NOT tokenize escaped variables', () => {
expect(mount(syntaxHighlighter('\\<<wat>>', 'json', { tokenizeVariables: true })).text()).toBe('<<wat>>');
expect(mount(syntaxHighlighter('<<wat\\>>', 'json', { tokenizeVariables: true })).text()).toBe('<<wat>>');
expect(mount(syntaxHighlighter('\\<<wat\\>>', 'json', { tokenizeVariables: true })).text()).toBe('<<wat>>');
});
});

describe('Supported languages', () => {
Expand Down
9 changes: 7 additions & 2 deletions src/codeMirror/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,14 @@ const extractVariables = (code, opts) => {
let offsetDelta = 0;
const variables = [];

const extracter = ({ length }, capture, offset) => {
const extracter = (match, capture, offset) => {
const unescaped = match.replace(/^\\<</, '<<').replace(/\\>>$/, '>>');
if (unescaped !== match) {
return unescaped;
}

variables.push({ text: capture, offset: offset - offsetDelta });
offsetDelta += length;
offsetDelta += match.length;

return '';
};
Expand Down

0 comments on commit f8e8de7

Please sign in to comment.