formatjs / formatjs-old

The monorepo home to all of the FormatJS related libraries.
https://formatjs.io/
156 stars 53 forks source link

Placeholder matching is not robust #534

Closed daggmano closed 4 years ago

daggmano commented 4 years ago

Which package? intl-messageformat

Describe the bug In formatters.ts, the generateId() method uses Date.now() to generate tokens for placeholders. If for some reason some of the Date methods are overridden, the token may then not match the TOKEN_REGEX format. It would be better to generate a token through a method that is less likely to be overridden.

To Reproduce Steps to reproduce the behavior:

  1. Create a React app using react-intl and create a message using placeholder / value substitution.
  2. Include in the page the date.js script from https://github.com/datejs/Datejs/blob/master/build/date.js (Yes, this old, but so is our codebase ;) )
  3. Run the app

Expected behavior Placeholders should be replaced by provided values.

CodeSandbox https://codesandbox.io/s/happy-field-sh5y0 Note that if the reference to date.js is removed from public/index.html line 26, the correct string appears.

longlho commented 4 years ago

oh boi... well I'm kinda impressed this doesn't break a ton of other things. We'll take a look soon

longlho commented 4 years ago

fixed in intl-messageformat@8.0.0