Skip to content

Fixes bugs related to unicode support in polynomial-hash functions - #304

Open
dubzzz wants to merge 6 commits into
trekhleb:masterfrom
dubzzz:polynomial
Open

dubzzz wants to merge 6 commits into
trekhleb:masterfrom
dubzzz:polynomial

Conversation

@dubzzz

@dubzzz dubzzz commented Feb 14, 2019 •

Copy link
Copy Markdown
Contributor

Details:

This Pull Request fixes bugs related to unicode support in polynomial-hash functions:

  • Method charToNumber of PolynomialHash was wrongly computed the code point value of a character: codePointAt is already aware of surrogate pairs (which is not the case of charCodeAt)
  • Method roll of PolynomialHash ignored unicode characters totally
  • SimplePolynomialHash was not aware of unicode

How did I find it?

Originally I wanted to check how I could rewrite the existing for-loop based tests into something based on property based. Then it clearly appeared that the test can be simplified given the switch to property based: roll(hash(XYZ), XYZ, YZA) === hash(YZA) whatever the values of X, Y, Z, A.

The final version of the test can be read as follow:
For any A single character, B single character and W string,
roll(hash(A + W), A + W, W + B) === hash(W + B)

As a side note, I strongly believe that adding such kind of tests would highly help to detect such bugs easily. Up to now it has detected the following: #100, #101, #102, #110 and #129.

And also #305, #306, #307, #308.

@codecov

codecov Bot commented Feb 14, 2019 •

Copy link
Copy Markdown

Codecov Report

Merging #304 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #304   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files         147    147           
  Lines        2591   2588    -3     
  Branches      432    431    -1     
=====================================
- Hits         2591   2588    -3
Impacted Files Coverage 螖
...yptography/polynomial-hash/SimplePolynomialHash.js 100% <100%> (酶) 猬嗭笍
...hms/cryptography/polynomial-hash/PolynomialHash.js 100% <100%> (酶) 猬嗭笍

Continue to review full report at Codecov.

Legend - Click here to learn more
螖 = absolute <relative> (impact), 酶 = not affected, ? = missing data
Powered by Codecov. Last update 1f39355...bd7d103. Read the comment docs.

@dubzzz

dubzzz commented Mar 3, 2019

Copy link
Copy Markdown
Contributor Author

@trekhleb Any updates? I can rebase the branch if needed

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

Successfully merging this pull request may close these issues.

1 participant