From aa8ab5b6e2a700828fb8439a0be5fe6ce4fae3ac Mon Sep 17 00:00:00 2001 From: Thomas Mair Date: Tue, 17 Jun 2025 09:43:25 +0200 Subject: [PATCH] fix: fix incorrect replacement of Object properties in REPLACEMENT constants --- lib/constants.js | 11 ++++++----- test/api.picomatch.js | 8 +++++++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/constants.js b/lib/constants.js index 27b3e20f..1e2d8d92 100644 --- a/lib/constants.js +++ b/lib/constants.js @@ -85,6 +85,11 @@ const POSIX_REGEX_SOURCE = { xdigit: 'A-Fa-f0-9' }; +const REPLACEMENTS = Object.create(null); +REPLACEMENTS['***'] = '*'; +REPLACEMENTS['**/**'] = '**'; +REPLACEMENTS['**/**/**'] = '**'; + module.exports = { MAX_LENGTH: 1024 * 64, POSIX_REGEX_SOURCE, @@ -98,11 +103,7 @@ module.exports = { REGEX_REMOVE_BACKSLASH: /(?:\[.*?[^\\]\]|\\(?=.))/g, // Replace globs with equivalent patterns to reduce parsing time. - REPLACEMENTS: { - '***': '*', - '**/**': '**', - '**/**/**': '**' - }, + REPLACEMENTS: REPLACEMENTS, // Digits CHAR_0: 48, /* 0 */ diff --git a/test/api.picomatch.js b/test/api.picomatch.js index 2fe67cff..24a554d3 100644 --- a/test/api.picomatch.js +++ b/test/api.picomatch.js @@ -2,7 +2,7 @@ const assert = require('assert'); const picomatch = require('..'); -const { isMatch } = picomatch; +const { isMatch, makeRe } = picomatch; const assertTokens = (actual, expected) => { const keyValuePairs = actual.map(token => [token.type, token.value]); @@ -378,4 +378,10 @@ describe('picomatch', () => { }); }); }); + + describe('makeRe', () => { + it('should work when supplying constructor as input', () => { + assert.strictEqual(makeRe('constructor').source, '^(?:^(?:constructor)$)$'); + }); + }); });