From f3c38400ff072de9aa1e1d9f93154dfa34e45128 Mon Sep 17 00:00:00 2001 From: reaper Date: Wed, 12 Nov 2025 14:40:30 +0530 Subject: [PATCH] test: Add test for restoring duplicate hashes in patternHasher --- packages/bruno-common/src/utils/template-hasher.spec.ts | 6 ++++++ packages/bruno-common/src/utils/template-hasher.ts | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/bruno-common/src/utils/template-hasher.spec.ts b/packages/bruno-common/src/utils/template-hasher.spec.ts index e4ad1aeee..bf42da033 100644 --- a/packages/bruno-common/src/utils/template-hasher.spec.ts +++ b/packages/bruno-common/src/utils/template-hasher.spec.ts @@ -29,4 +29,10 @@ describe('patternHasher', () => { expect(hashed).toMatchInlineSnapshot(`"$name.example.com"`); expect(restore(hashed)).toEqual(originalUrl); }); + + it('verify restoring duplicate hashes', () => { + const originalJSON = `{"name":"{{name}}","x":"{{name}}", "y":"{{name}}"}`; + const { hashed, restore } = patternHasher(originalJSON); + expect(restore(hashed)).toEqual(originalJSON); + }); }); diff --git a/packages/bruno-common/src/utils/template-hasher.ts b/packages/bruno-common/src/utils/template-hasher.ts index 290c8a3e9..b7b5b0218 100644 --- a/packages/bruno-common/src/utils/template-hasher.ts +++ b/packages/bruno-common/src/utils/template-hasher.ts @@ -41,7 +41,7 @@ export function patternHasher(input: string, pattern: string | RegExp = VARIABLE let clone = current; for (const hash in hashToOriginal) { const value = hashToOriginal[hash]; - clone = clone.replace(hash, value); + clone = clone.replace(new RegExp(`(${hash})`, 'g'), value); } return clone; }