From fc2edef61909dc5797cee601ed8f47f6e6a9165d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Parmentier?= Date: Fri, 23 Jul 2021 10:20:48 +0200 Subject: [PATCH] fix(transformers): non string search value non string search value was not stringified in REPLACE --- packages/transformers/src/operations/REPLACE_REGEX.js | 2 +- packages/transformers/src/operations/REPLACE_REGEX.spec.js | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/transformers/src/operations/REPLACE_REGEX.js b/packages/transformers/src/operations/REPLACE_REGEX.js index 25aff337..7eba24b1 100644 --- a/packages/transformers/src/operations/REPLACE_REGEX.js +++ b/packages/transformers/src/operations/REPLACE_REGEX.js @@ -1,7 +1,7 @@ import { transformerWithTwoArgs } from './transformer'; export const replace = (value, searchValue, replaceValue) => { - const template = typeof input === 'string' ? searchValue : searchValue.toString(); + const template = typeof searchValue === 'string' ? searchValue : searchValue.toString(); const cleantemplate = template.trim().replace(/^[/]+/, '').replace(/[/]+$/, ''); return value.replace(RegExp(cleantemplate, 'gi'), replaceValue); }; diff --git a/packages/transformers/src/operations/REPLACE_REGEX.spec.js b/packages/transformers/src/operations/REPLACE_REGEX.spec.js index bd4fe036..ffbab866 100644 --- a/packages/transformers/src/operations/REPLACE_REGEX.spec.js +++ b/packages/transformers/src/operations/REPLACE_REGEX.spec.js @@ -13,4 +13,7 @@ describe('REPLACE_REGEX', () => { it('should return new value from string', () => { expect(replace('hello world', '\\s*wo\\w+', '')).toBe('hello'); }); + it('should return new value from number search value', () => { + expect(replace('1', 1, '2')).toBe('2'); + }); });