Skip to content

Commit 21094b8

Browse files
authored
fix(mdx-variable-regex): user variable display in SuperHub read mode (#250)
1 parent de0ecd0 commit 21094b8

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

__tests__/index.test.jsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,4 +279,11 @@ describe('MDX_VARIABLE_REGEXP', () => {
279279
expect('{user.what_the\rfuck}').not.toMatch(new RegExp(MDX_VARIABLE_REGEXP));
280280
expect('{user.what_the\r\nfuck}').not.toMatch(new RegExp(MDX_VARIABLE_REGEXP));
281281
});
282+
283+
it('should NOT match JS template literals without a dot after user', () => {
284+
// Bug case: {userXYZ} should not match as if it were {user.XYZ}
285+
expect('{userEndpoint}').not.toMatch(new RegExp(MDX_VARIABLE_REGEXP));
286+
expect('{userXYZ}').not.toMatch(new RegExp(MDX_VARIABLE_REGEXP));
287+
expect('{baseUrl}').not.toMatch(new RegExp(MDX_VARIABLE_REGEXP));
288+
});
282289
});

index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ module.exports.VARIABLE_REGEXP = /(?:\\)?<<((?:(?![\r\n])[-_\p{L}:.\s\d])+)(?:\\
204204
* @see {@link https://stackoverflow.com/a/6926184}
205205
*/
206206
module.exports.MDX_VARIABLE_REGEXP =
207-
/(\\)?\{user.([$_\p{L}][$_\p{L}\p{Mn}\p{Mc}\p{Nd}\p{Pc}\u200C\u200D]*)(\\)?\}/iu.source;
207+
/(\\)?\{user\.([$_\p{L}][$_\p{L}\p{Mn}\p{Mc}\p{Nd}\p{Pc}\u200C\u200D]*)(\\)?\}/iu.source;
208208

209209
module.exports.VariablesContext = VariablesContext;
210210
module.exports.SelectedAppContext = SelectedAppContext;

0 commit comments

Comments
 (0)