Don't compare zero exponentials in strings as equal #6749
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Infamously,
md5('240610708') == md5('QNKCDZO')
returns true in PHP. The reason is that' 0e462097431906509019562988736854' == '0e830400451993494058024219903391'
interprets the two hashes as floating point numbers in exponential notation, and any numbers of the form0eNNNN
evaluate to zero. Thus the strings are considered equal. This is usually not desirable.This patch changes the string comparison rules to treat strings that contain an exponential of the form
0eNNNN
differently: If both sides of the comparison are a zero-exponential, then the strings will be compared lexicographically instead (which means they are only equal if they're exactly equal). If at least one side is not a zero-exponential, then the usual rules apply. We already have a similar special case for integral numbers overflowing the integer space.