Skip to content
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

[KT-69327] Correct FloatingPointParser.initialParse method to handle specific cases with invalid exponent string value #5322

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Correct floating point parser behavior
  • Loading branch information
OptimumCode committed Jun 25, 2024
commit 45434567e6876e51be29aa86d393f0e0456fadc2
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,13 @@ internal object FloatingPointParser {

var exponentOffset = end + 1
if (s[exponentOffset] == '+') {
if (s[exponentOffset + 1] == '-') {
throw NumberFormatException(s)
}
exponentOffset++ // skip the plus sign
if (exponentOffset == length)
throw NumberFormatException(s)

if (s[exponentOffset] == '-') {
throw NumberFormatException(s)
}
}
val strExp = s.substring(exponentOffset, length)
try {
Expand All @@ -221,7 +222,9 @@ internal object FloatingPointParser {
for (i in strExp.indices) {
ch = strExp[i]
if (ch < '0' || ch > '9') {
if (i == 0 && ch == '-')
// minus character is only valid
// if it is not the only one in the exponent string
if (i == 0 && ch == '-' && strExp.length > 1)
continue
// ex contains the exponent substring only so throw
// a new exception with the correct string.
Expand Down
-