From 823cdaae528c68d3866a0ef4c0a071c7f19c895b Mon Sep 17 00:00:00 2001 From: dd Date: Fri, 21 Jul 2023 14:31:42 +0800 Subject: [PATCH 1/2] fix: escape the regexp pattern to support the build metadata section of version string --- lib/provider/cli.js | 3 ++- lib/util.js | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/provider/cli.js b/lib/provider/cli.js index ff27eb5..2613318 100644 --- a/lib/provider/cli.js +++ b/lib/provider/cli.js @@ -8,6 +8,7 @@ const { exec } = require('node:child_process'); const { isValidNamespace, isValidName, isValidVersion, isValidProtocol } = require('../cli-helpers'); const { genShaSums, sign, exportPublicKey, publish } = require('./provider'); +const { escapeRegExp } = require('../util'); const registryAddr = process.env.CITIZEN_ADDR || 'http://127.0.0.1:3000'; @@ -78,7 +79,7 @@ module.exports = async (namespace, type, version, protocols, cmd) => { spinner.start(); const files = await readdir(targetDir); - const providerRegex = new RegExp(`${fileNamePrefix}_(?.*)_(?.*).zip`); + const providerRegex = new RegExp(`${escapeRegExp(fileNamePrefix)}_(?.*)_(?.*).zip`); const providerArchives = files.filter((f) => f.match(providerRegex)); if (providerArchives.length === 0) { diff --git a/lib/util.js b/lib/util.js index c7a7dda..aff3ead 100644 --- a/lib/util.js +++ b/lib/util.js @@ -198,9 +198,14 @@ const normalizeSqlitePath = () => { } }; +const escapeRegExp = (str) => { + return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); +}; + module.exports = { makeUrl, parseHcl, extractShasum, normalizeSqlitePath, + escapeRegExp, }; From 47ab983cf9f587663ff106c8afedd164db750792 Mon Sep 17 00:00:00 2001 From: dd Date: Wed, 26 Jul 2023 15:37:06 +0800 Subject: [PATCH 2/2] fix: escape '.zip' also --- lib/provider/cli.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/provider/cli.js b/lib/provider/cli.js index 2613318..02050fc 100644 --- a/lib/provider/cli.js +++ b/lib/provider/cli.js @@ -79,7 +79,7 @@ module.exports = async (namespace, type, version, protocols, cmd) => { spinner.start(); const files = await readdir(targetDir); - const providerRegex = new RegExp(`${escapeRegExp(fileNamePrefix)}_(?.*)_(?.*).zip`); + const providerRegex = new RegExp(`${escapeRegExp(fileNamePrefix)}_(?.*)_(?.*)\\.zip`); const providerArchives = files.filter((f) => f.match(providerRegex)); if (providerArchives.length === 0) {