From e289482a00e3a953d32db039fe10cb81fdac0186 Mon Sep 17 00:00:00 2001 From: amalej Date: Thu, 11 Dec 2025 06:32:19 +0800 Subject: [PATCH 1/2] fix issue with regex parsing [@version> --- src/onfire-cli.ts | 4 +++- tests/onfire-cli.test.ts | 35 +++++++++++++++++++++++++++-------- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/onfire-cli.ts b/src/onfire-cli.ts index e360ad6..16e38ea 100644 --- a/src/onfire-cli.ts +++ b/src/onfire-cli.ts @@ -411,7 +411,9 @@ export class OnFireCLI extends CommandLineInterface { ); } else { // TODO: improve matching. try to avoid using regex - const regExp = new RegExp(`(\\b${highlight}\\b)(?!.*\\1)`); + const safeHighlightRegExp = + highlight?.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") ?? ""; + const regExp = new RegExp(`(\\b${safeHighlightRegExp}\\b)(?!.*\\1)`); console.log( `${this.textBold(this.textYellow("Usage:"))} ${cmdConfig.usage.replace( regExp, diff --git a/tests/onfire-cli.test.ts b/tests/onfire-cli.test.ts index 7fa05ef..af1a656 100644 --- a/tests/onfire-cli.test.ts +++ b/tests/onfire-cli.test.ts @@ -473,16 +473,14 @@ describe("Test getting rendering list", () => { }); describe("Load commands to render", () => { - beforeAll(() => { - onfireCLI._setInput("appdistribution"); - }); - it("Should show that there are 5 commands to render", () => { + onfireCLI._setInput("appdistribution"); const renderMessage = onfireCLI._getCommandsToRender(); expect(renderMessage.length).toEqual(5); }); it("Should show that the selected command in index [0] is 'appdistribution:distribute -> upload a release binary and optionally distribute it to testers and run automated tests'", () => { + onfireCLI._setInput("appdistribution"); const renderMessage = onfireCLI._getCommandsToRender(); const cmdLabel = `-> upload a release binary and optionally distribute it to testers and run automated tests`; expect(renderMessage[0]).toEqual( @@ -492,7 +490,17 @@ describe("Test getting rendering list", () => { ); }); + it("Should show that the unselected command in index [1] is 'functions:secrets:access -> access secret value given secret and its version. Defaults to accessing the latest version'", () => { + onfireCLI._setInput("functionseec"); + const renderMessage = onfireCLI._getCommandsToRender(); + const cmdLabel = `-> access secret value given secret and its version. Defaults to accessing the latest version`; + expect(renderMessage[1]).toEqual( + ` ${cli._textBold("functions:secrets:access")} ${cmdLabel}\x1b[K` + ); + }); + it("Should show that the unselected command in index [2] is 'appdistribution:testers:add -> add testers to project (and App Distribution group, if specified via flag)'", () => { + onfireCLI._setInput("appdistribution"); const renderMessage = onfireCLI._getCommandsToRender(); const cmdLabel = `-> add testers to project (and App Distribution group, if specified via flag)`; expect(renderMessage[2]).toEqual( @@ -533,18 +541,18 @@ describe("Test getting rendering list", () => { }); describe("Test partial matching", () => { - beforeAll(() => { - const command = "emss"; + const setCliInput = (command: string) => { onfireCLI._setInput(command); onfireCLI._setCursorPosition(onfireCLI.prefix.length + command.length); - }); - + }; it("Should show that there are 5 options to render", () => { + setCliInput("emss"); const renderMessage = onfireCLI._getCommandsToRender(); expect(renderMessage.length).toEqual(5); }); it("Should show that the selected option in index [0] is 'emulators:start -> start the local Firebase emulators'", () => { + setCliInput("emss"); const renderMessage = onfireCLI._getCommandsToRender(); const cmdLabel = `-> start the local Firebase emulators`; expect(renderMessage[0]).toEqual( @@ -553,6 +561,17 @@ describe("Test getting rendering list", () => { )} ${cli._textGreen(cmdLabel)}\x1b[K` ); }); + + it("Should show that the selected option in index [0] is 'functions:secrets:access -> access secret value given secret and its version. Defaults to accessing the latest version'", () => { + setCliInput("funcsecacess"); + const renderMessage = onfireCLI._getCommandsToRender(); + const cmdLabel = `-> access secret value given secret and its version. Defaults to accessing the latest version`; + expect(renderMessage[0]).toEqual( + `${cli._textCyan(cli._textBold(">"))} ${cli._textGreen( + cli._textBold("functions:secrets:access") + )} ${cli._textGreen(cmdLabel)}\x1b[K` + ); + }); }); }); From 6daeab3347d068673c13e23ab96ad0d7364cffb7 Mon Sep 17 00:00:00 2001 From: amalej Date: Thu, 11 Dec 2025 06:36:00 +0800 Subject: [PATCH 2/2] added changelog entry --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b96c35..3fc2f69 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ +Unreleased + +- Fix issue with regex parsing `[@version>` + - This happens when typing commands like `functions:secrets:access` + v1.4.0 - Fixed issue where Onfire CLI cannot parse commands on firebase-tools v15