Commit 68ce690
fix: use Math.imul in simpleHash to prevent float precision loss
The FNV-1 hash requires 32-bit integer arithmetic. Using plain * in
JavaScript allows intermediate products to exceed Number.MAX_SAFE_INTEGER
(~9e15), causing float64 precision loss and a non-standard hash result.
Math.imul() performs C-style 32-bit integer multiplication and is
available in all modern browsers; the final >>> 0 already normalises h
to uint32, so this is a drop-in fix.
The bug only affected makeKey() fallback cases where both item.guid and
item.link are empty (those items are never bookmarked anyway), so there
is no user-visible behavioural change, but the hash is now correct.
Adds a regression test verifying that distinct title+published strings
produce distinct fallback keys and that the same items deduplicate on the
second call.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>1 parent b525f07 commit 68ce690
2 files changed
Lines changed: 33 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
122 | 122 | | |
123 | 123 | | |
124 | 124 | | |
125 | | - | |
| 125 | + | |
| 126 | + | |
126 | 127 | | |
127 | 128 | | |
128 | 129 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
205 | 205 | | |
206 | 206 | | |
207 | 207 | | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
0 commit comments