diff --git a/__tests__/index.test.jsx b/__tests__/index.test.jsx index 51dd14e..90c69a1 100644 --- a/__tests__/index.test.jsx +++ b/__tests__/index.test.jsx @@ -279,4 +279,11 @@ describe('MDX_VARIABLE_REGEXP', () => { expect('{user.what_the\rfuck}').not.toMatch(new RegExp(MDX_VARIABLE_REGEXP)); expect('{user.what_the\r\nfuck}').not.toMatch(new RegExp(MDX_VARIABLE_REGEXP)); }); + + it('should NOT match JS template literals without a dot after user', () => { + // Bug case: {userXYZ} should not match as if it were {user.XYZ} + expect('{userEndpoint}').not.toMatch(new RegExp(MDX_VARIABLE_REGEXP)); + expect('{userXYZ}').not.toMatch(new RegExp(MDX_VARIABLE_REGEXP)); + expect('{baseUrl}').not.toMatch(new RegExp(MDX_VARIABLE_REGEXP)); + }); }); diff --git a/index.jsx b/index.jsx index f9f6b89..281bef0 100644 --- a/index.jsx +++ b/index.jsx @@ -204,7 +204,7 @@ module.exports.VARIABLE_REGEXP = /(?:\\)?<<((?:(?![\r\n])[-_\p{L}:.\s\d])+)(?:\\ * @see {@link https://stackoverflow.com/a/6926184} */ module.exports.MDX_VARIABLE_REGEXP = - /(\\)?\{user.([$_\p{L}][$_\p{L}\p{Mn}\p{Mc}\p{Nd}\p{Pc}\u200C\u200D]*)(\\)?\}/iu.source; + /(\\)?\{user\.([$_\p{L}][$_\p{L}\p{Mn}\p{Mc}\p{Nd}\p{Pc}\u200C\u200D]*)(\\)?\}/iu.source; module.exports.VariablesContext = VariablesContext; module.exports.SelectedAppContext = SelectedAppContext;