Skip to content

Commit f8e8de7

Browse files
fix: dont variable-ize escaped sequences (#458)
* fix: dont variable-ize escaped sequences * chore: oops
1 parent f720e06 commit f8e8de7

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

__tests__/codeMirror.test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ describe('variable substitution', () => {
9797
'APIKEY NAME'
9898
);
9999
});
100+
101+
it('should NOT tokenize escaped variables', () => {
102+
expect(mount(syntaxHighlighter('\\<<wat>>', 'json', { tokenizeVariables: true })).text()).toBe('<<wat>>');
103+
expect(mount(syntaxHighlighter('<<wat\\>>', 'json', { tokenizeVariables: true })).text()).toBe('<<wat>>');
104+
expect(mount(syntaxHighlighter('\\<<wat\\>>', 'json', { tokenizeVariables: true })).text()).toBe('<<wat>>');
105+
});
100106
});
101107

102108
describe('Supported languages', () => {

src/codeMirror/index.jsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,14 @@ const extractVariables = (code, opts) => {
169169
let offsetDelta = 0;
170170
const variables = [];
171171

172-
const extracter = ({ length }, capture, offset) => {
172+
const extracter = (match, capture, offset) => {
173+
const unescaped = match.replace(/^\\<</, '<<').replace(/\\>>$/, '>>');
174+
if (unescaped !== match) {
175+
return unescaped;
176+
}
177+
173178
variables.push({ text: capture, offset: offset - offsetDelta });
174-
offsetDelta += length;
179+
offsetDelta += match.length;
175180

176181
return '';
177182
};

0 commit comments

Comments
 (0)