Skip to content

Commit 0f51a34

Browse files
fix(mf1/parser): Use correct regexp for 'quoted' escapes (fixes #436)
1 parent 434a2c1 commit 0f51a34

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

mf1/packages/parser/src/lexer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export const states: { [state: string]: Rules } = {
55
doubleapos: { match: "''", value: () => "'" },
66
quoted: {
77
lineBreaks: true,
8-
match: /'[{}#](?:[^]*?[^'])?'(?!')/u,
8+
match: /'[{}#](?:[^']|'')*'(?!')/u,
99
value: src => src.slice(1, -1).replace(/''/g, "'")
1010
},
1111
argument: {

mf1/packages/parser/src/parser.test.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function run(shape: Record<string, any>) {
2626
}
2727
}
2828

29-
const trimCtx = obj =>
29+
const trimCtx = (obj: any) =>
3030
JSON.parse(
3131
JSON.stringify(obj, (key, value) => (key === 'ctx' ? undefined : value))
3232
);
@@ -297,6 +297,23 @@ describe('Plurals', () => {
297297
{ type: 'content', value: 'one' },
298298
{ type: 'octothorpe' }
299299
]);
300+
expect(parse("'{' {S, plural, other{# is a '#'}} '}'")).toMatchObject([
301+
{ type: 'content', value: '{ ' },
302+
{
303+
type: 'plural',
304+
arg: 'S',
305+
cases: [
306+
{
307+
key: 'other',
308+
tokens: [
309+
{ type: 'octothorpe' },
310+
{ type: 'content', value: ' is a #' }
311+
]
312+
}
313+
]
314+
},
315+
{ type: 'content', value: ' }' }
316+
]);
300317
});
301318

302319
it('should handle octothorpes with nested plurals', () => {

0 commit comments

Comments
 (0)