messageformat / parser

A PEG.js parser for ICU MessageFormat strings
https://messageformat.github.io/
MIT License
7 stars 5 forks source link

Handling of apostrophes is incorrect #2

Closed nkovacs closed 7 years ago

nkovacs commented 7 years ago

Copied from https://github.com/messageformat/messageformat.js/issues/175

messageformat.js does not handle double apostrophes correctly.

var mf = new MessageFormat('en');

console.log(mf.compile("I see '{many}'")());
console.log(mf.compile("I said '{''Wow!''}'")());
console.log(mf.compile("I don't know")());
console.log(mf.compile("I don''t know")());

This should output (assuming DOUBLE_OPTIONAL):

  1. I see {many}
  2. I said {'Wow!'}
  3. I don't know
  4. I don't know

The first two don't work at all, and the fourth one outputs two single quotes instead of one.

See http://icu-project.org/apiref/icu4j/com/ibm/icu/text/MessagePattern.ApostropheMode.html and http://userguide.icu-project.org/formatparse/messages#TOC-Quoting-Escaping