Conversation
|
To my understanding, a typical HEX should not be odd.. it should always be even. You could 'pad' either in the front or back, depending where you want the bytes shifted...and that is inherently ambiguous in general 🤷♂️ php decided to turn down a bug report for a similar behavior; and continue returning an error/warning when odd-length hex string is detected. Not sure if it makes more sense to throw an error/warning here or to do what you've done in your PR. |
| // Shortcut | ||
| var hexStrLength = hexStr.length; | ||
| if( hexStrLength % 2 === 1 ){ | ||
| hexStr = '0' + hexStr |
There was a problem hiding this comment.
| hexStr = '0' + hexStr | |
| hexStr = '0' + hexStr; | |
| var hexStrLength = hexStr.length; | ||
| if( hexStrLength % 2 === 1 ){ | ||
| hexStr = '0' + hexStr | ||
| hexStrLength = hexStrLength + 1 |
There was a problem hiding this comment.
| hexStrLength = hexStrLength + 1 | |
| hexStrLength = hexStrLength + 1; | |
OptimusPi
left a comment
There was a problem hiding this comment.
Would be great to have a unit test proving this works for even and odd strings.
|
How do you get an odd length hex string, and how do you decide if start or end need padding? This feels more like a |
I met problems while I referred to the library.
I reviewed the source code, then I located the bug:
It was supposed that hexStrLengh is even. The problem will recur if hexStrLengh is odd.
Finally, I fix the problem and commit the solution.