-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix a problem when hexStrLength is odd #329
base: develop
Are you sure you want to change the base?
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. |
@@ -414,6 +414,10 @@ var CryptoJS = CryptoJS || (function (Math, undefined) { | |||
parse: function (hexStr) { | |||
// Shortcut | |||
var hexStrLength = hexStr.length; | |||
if( hexStrLength % 2 === 1 ){ | |||
hexStr = '0' + hexStr |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hexStr = '0' + hexStr | |
hexStr = '0' + hexStr; | |
@@ -414,6 +414,10 @@ var CryptoJS = CryptoJS || (function (Math, undefined) { | |||
parse: function (hexStr) { | |||
// Shortcut | |||
var hexStrLength = hexStr.length; | |||
if( hexStrLength % 2 === 1 ){ | |||
hexStr = '0' + hexStr | |||
hexStrLength = hexStrLength + 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hexStrLength = hexStrLength + 1 | |
hexStrLength = hexStrLength + 1; | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.