globalizejs / globalizejs/globalize

Hash collision for runtime keys (bug)

Open
#609 1 comment 0 reactions 0 assignees View on GitHub
bug runtime
Dominant language
JavaScript
Stars
4.8k
Forks
585
PR merge metrics
No merged PRs in 30d

Description

Looking a bit into how you generate the runtime keys for production builds, I noticed you are using a hash function (relevant files: [runtime-key.js](https://github.com/jquery/globalize/blob/master/src/common/runtime-key.js) and [hash.js](https://github.com/jquery/globalize/blob/master/src/util/string/hash.js)). This issue probably doesn't occur often; but I'm wondering what is the correct behavior when there is a collision between generated keys, i.e. the hash function generates the same thing for distinct objects.

So I've written a sample test case with message keys `"Z@S.ME"` and `"Z@RN.E"` (these keys will collide according to http://stackoverflow.com/a/6120672). The end result is only one of the strings is in the compiled bundle. Here is my my test case:

```
var Globalize = require("globalize");
Globalize.load(require("cldr-data").entireSupplemental());
Globalize.load(require("cldr-data").entireMainFor("pt"));
Globalize.loadMessages({
pt: {
"Z@S.ME": "my first string",
"Z@RN.E": "my second string"
}
});
var GlobalizeCompiler = require("globalize-compiler");
var fs = require('fs');
fs.writeFile("output.js", GlobalizeCompiler.compile([
Globalize("pt").messageFormatter("Z@S.ME"),
Globalize("pt").messageFormatter("Z@RN.E"),
]));
```

In the output there's only one message function with key `a1793498274`, that contains the first string. Obviously at this point `console.log(Globalize("pt").messageFormatter("Z@RN.E")())` also gives the incorrect string.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.