From b2ae17697dc9ebfccbd549ca95bdc0469017ee63 Mon Sep 17 00:00:00 2001 From: Kim Biesbjerg Date: Wed, 5 Jul 2017 15:43:54 +0200 Subject: [PATCH] Replace all occurences of escaped quotes. --- src/parsers/pipe.parser.ts | 2 +- tests/parsers/pipe.parser.spec.ts | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/parsers/pipe.parser.ts b/src/parsers/pipe.parser.ts index 321418d..604f6fc 100644 --- a/src/parsers/pipe.parser.ts +++ b/src/parsers/pipe.parser.ts @@ -18,7 +18,7 @@ export class PipeParser extends AbstractTemplateParser implements ParserInterfac const regExp: RegExp = /(['"`])((?:(?!\1).|\\\1)+)\1\s*\|\s*translate/g; let matches: RegExpExecArray; while (matches = regExp.exec(template)) { - collection = collection.add(matches[2].replace('\\\'', '\'')); + collection = collection.add(matches[2].split('\\\'').join('\'')); } return collection; diff --git a/tests/parsers/pipe.parser.spec.ts b/tests/parsers/pipe.parser.spec.ts index 1d8a5e7..0926ffd 100644 --- a/tests/parsers/pipe.parser.spec.ts +++ b/tests/parsers/pipe.parser.spec.ts @@ -36,6 +36,12 @@ describe('PipeParser', () => { expect(keys).to.deep.equal([`World's largest potato`]); }); + it('should extract strings with multiple escaped quotes', () => { + const contents = `{{ 'C\\'est ok. C\\'est ok' | translate }}`; + const keys = parser.extract(contents, templateFilename).keys(); + expect(keys).to.deep.equal([`C'est ok. C'est ok`]); + }); + it('should extract interpolated strings using translate pipe in attributes', () => { const contents = ``; const keys = parser.extract(contents, templateFilename).keys();