mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-24 13:15:40 +00:00
test: Add test for restoring duplicate hashes in patternHasher
This commit is contained in:
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user