[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect runtime hash due to control characters in JSON.stringify results #848

Open
dpolivy opened this issue Dec 3, 2018 · 0 comments

Comments

@dpolivy
Copy link
dpolivy commented Dec 3, 2018

I'm running into some issues with the runtime parameter hashing of globalize due to embedded Unicode control characters being escaped during calls to JSON.stringify. This is happening with Left-to-right and Right-to-left control characters (e.g. \u200e), and results in the runtime hash not matching the pre-compiled hash value of the formatters.

My environment is a little unique; I am running globalize successfully (aside from this issue!) in a Classic ASP page using Microsoft JScript (ECMAScript 3-ish). It does require the use of es5-shim and a JSON library, in my case, currently, json2.

The issue is that json2 is escaping a larger set of Unicode control characters than other JS implementations.

For example, my compiled formatter looks like this:

Globalize.a1955837365 = currencyFormatterFn(Globalize("fa-IR").numberFormatter({"maximumFractionDigits":0,"minimumFractionDigits":0,"raw":"‎'DOP' #,##0.00"}));

When the arguments for this are stringified, it turns into this:

[{"maximumFractionDigits":0,"minimumFractionDigits":0,"raw":"\u200e'DOP' #,##0.00"}]

And, when that is hashed, the \u200e character is hashed as [92][117][50][48][48][101] instead if [8206], resulting in a hash mis-match.

I'm not sure the best way to fix this -- should the hashing algorithm be more robust to handle control characters consistently? Do I need to modify json2.js to not escape these characters and behave more like other browsers? I expect the json2.js behavior is intentionally the way it is, and the JSON spec allows for escaping unicode control characters, so this is technically correct, it's just not consistent for use as a hash input.

This seems related to #705, and a fix for that might/should take this into account.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant