From e2fe14d9515e65d01f467cc69dae8c449d8281e8 Mon Sep 17 00:00:00 2001 From: rikkarth Date: Sat, 16 Mar 2024 00:48:58 +0000 Subject: [PATCH] fix(#871-strictMode): replaced stream with conventional loop for 1.6 compatibility --- src/main/java/org/json/JSONTokener.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/json/JSONTokener.java b/src/main/java/org/json/JSONTokener.java index 62ef75b..48a5c75 100644 --- a/src/main/java/org/json/JSONTokener.java +++ b/src/main/java/org/json/JSONTokener.java @@ -396,7 +396,7 @@ public class JSONTokener { public String nextTo(String delimiters) throws JSONException { char c; StringBuilder sb = new StringBuilder(); - for (;;) { + for (; ; ) { c = this.next(); if (delimiters.indexOf(c) >= 0 || c == 0 || c == '\n' || c == '\r') { @@ -457,9 +457,9 @@ public class JSONTokener { if (strictMode) { Object valueToValidate = nextSimpleValue(c, true); - boolean isNumeric = valueToValidate.toString().chars().allMatch( Character::isDigit ); + boolean isNumeric = checkIfValueIsNumeric(valueToValidate); - if(isNumeric){ + if (isNumeric) { return valueToValidate; } @@ -475,6 +475,15 @@ public class JSONTokener { return nextSimpleValue(c); } + private boolean checkIfValueIsNumeric(Object valueToValidate) { + for (char c : valueToValidate.toString().toCharArray()) { + if (!Character.isDigit(c)) { + return false; + } + } + return true; + } + /** * This method is used to get a JSONObject from the JSONTokener. The strictMode parameter controls the behavior of * the method when parsing the JSONObject.