diff --git a/scripts/bump-dependent-playgrounds.ts b/scripts/bump-dependent-playgrounds.ts index 93fc2b7b..000c3306 100644 --- a/scripts/bump-dependent-playgrounds.ts +++ b/scripts/bump-dependent-playgrounds.ts @@ -202,6 +202,17 @@ async function bumpPlaygroundIfNeeded( return true; } +/** + * Escapes regular-expression metacharacters so a string can be safely embedded + * in a dynamically-constructed `RegExp`. + * + * @param value - The raw string to escape. + * @returns The string with all regex metacharacters escaped. + */ +function escapeRegExp(value: string): string { + return value.replace(/[.*+?^${}()|[\]\\]/gu, '\\$&'); +} + /** * Updates the CHANGELOG.md file for a playground package. * @@ -238,7 +249,7 @@ ${depsList} // Update the links at the bottom const unreleasedLinkPattern = new RegExp( - `\\[Unreleased\\]: (https://github\\.com/MetaMask/connect-monorepo/compare/${packageName.replace(/\//gu, '\\/')}@)[\\d.]+\\.\\.\\.HEAD`, + `\\[Unreleased\\]: (https://github\\.com/MetaMask/connect-monorepo/compare/${escapeRegExp(packageName)}@)[\\d.]+\\.\\.\\.HEAD`, 'u', );