Commit 45aefd4
fix(LCS): use Object.create(null) so prototype members don't shadow lookups
LCS stores equivalence classes in a plain object, so input elements that
match Object.prototype member names (`constructor`, `__proto__`,
`toString`, `hasOwnProperty`, etc.) hit the prototype-inherited member
on the lookup and crash with:
TypeError: equivalenceClasses[item].push is not a function
`Object.create(null)` produces a dictionary with no prototype chain, so
the lookup sees the key only if we wrote it. Zero API change.
Regression test in test/LCS.test.js covers the common prototype names.
Closes #861 parent 6824b46 commit 45aefd4
2 files changed
Lines changed: 26 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
26 | 29 | | |
27 | 30 | | |
28 | 31 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
34 | 56 | | |
0 commit comments