Skip to content

Commit

Permalink
stleary#653 - review comments updated.
Browse files Browse the repository at this point in the history
  • Loading branch information
rudrajyotib committed Oct 12, 2023
1 parent 0cdc38a commit 56cb5f8
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/main/java/org/json/JSONObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -2416,17 +2416,16 @@ protected static Number stringToNumber(final String input) throws NumberFormatEx
try {
Double d = Double.valueOf(val);
if(d.isNaN() || d.isInfinite()) {
throw new NumberFormatException("val ["+val+"] is not a valid number.");
throw new NumberFormatException("val ["+input+"] is not a valid number.");
}
return d;
} catch (NumberFormatException ignore) {
throw new NumberFormatException("val ["+val+"] is not a valid number.");
throw new NumberFormatException("val ["+input+"] is not a valid number.");
}
}
}
val = removeLeadingZerosOfNumber(input);
initial = val.charAt(0);
// block items like 00 01 etc. Java number parsers treat these as Octal.
if(initial == '0' && val.length() > 1) {
char at1 = val.charAt(1);
if(at1 >= '0' && at1 <= '9') {
Expand Down Expand Up @@ -2934,10 +2933,12 @@ private static String removeLeadingZerosOfNumber(String value){
int counter = negativeFirstChar ? 1:0;
while (counter < value.length()){
if (value.charAt(counter) != '0'){
return String.format("%s%s", negativeFirstChar?'-':"",value.substring(counter));
if (negativeFirstChar) {return "-".concat(value.substring(counter));}
return value.substring(counter);
}
++counter;
}
return String.format("%s%s", negativeFirstChar?'-':"",'0');
if (negativeFirstChar) {return "-0";}
return "0";
}
}

0 comments on commit 56cb5f8

Please sign in to comment.