代码拉取完成,页面将自动刷新
From a0c4a0eae277130e22979cf307c95dec4005a78e Mon Sep 17 00:00:00 2001
From: Andres Almiray <aalmiray@gmail.com>
Date: Thu, 26 Sep 2024 17:47:11 -0500
Subject: [PATCH] fix: Handle unbalanced comment string
---
.../src/main/java/net/sf/json/util/JSONTokener.java | 2 ++
.../src/test/java/net/sf/json/TestJSONSerializer.java | 9 +++++++++
src/main/java/net/sf/json/util/JSONTokener.java | 2 ++
src/test/java/net/sf/json/TestJSONSerializer.java | 9 +++++++++
4 files changed, 22 insertions(+)
diff --git a/jenkins-json-lib-2.4/src/main/java/net/sf/json/util/JSONTokener.java b/jenkins-json-lib-2.4/src/main/java/net/sf/json/util/JSONTokener.java
index 655cd7c..aad6f3b 100644
--- a/jenkins-json-lib-2.4/src/main/java/net/sf/json/util/JSONTokener.java
+++ b/jenkins-json-lib-2.4/src/main/java/net/sf/json/util/JSONTokener.java
@@ -192,6 +192,8 @@ public class JSONTokener {
if (c == '*') {
if (next() == '/') {
break;
+ } else if (!more()) {
+ return 0;
}
back();
}
diff --git a/jenkins-json-lib-2.4/src/test/java/net/sf/json/TestJSONSerializer.java b/jenkins-json-lib-2.4/src/test/java/net/sf/json/TestJSONSerializer.java
index 6a15863..d0c9ff4 100644
--- a/jenkins-json-lib-2.4/src/test/java/net/sf/json/TestJSONSerializer.java
+++ b/jenkins-json-lib-2.4/src/test/java/net/sf/json/TestJSONSerializer.java
@@ -139,6 +139,15 @@ public class TestJSONSerializer extends TestCase {
assertEquals(beanB.getValue(), ((ValueBean) bb).getValue());
}
+ public void testToJava_JSONObject_5() throws Exception {
+ try {
+ JSONObject.fromObject("/**");
+ fail("Should have thrown a JSONException");
+ } catch (JSONException expected) {
+ // ok
+ }
+ }
+
public void testToJava_JSONObject_and_reset() throws Exception {
String json = "{bool:true,integer:1,string:\"json\"}";
JSONObject jsonObject = JSONObject.fromObject(json);
diff --git a/src/main/java/net/sf/json/util/JSONTokener.java b/src/main/java/net/sf/json/util/JSONTokener.java
index 4f6ff94..0cdde2b 100644
--- a/src/main/java/net/sf/json/util/JSONTokener.java
+++ b/src/main/java/net/sf/json/util/JSONTokener.java
@@ -196,6 +196,8 @@ public class JSONTokener {
if( c == '*' ){
if( next() == '/' ){
break;
+ } else if (!more()){
+ return 0;
}
back();
}
diff --git a/src/test/java/net/sf/json/TestJSONSerializer.java b/src/test/java/net/sf/json/TestJSONSerializer.java
index 7397769..89c145d 100644
--- a/src/test/java/net/sf/json/TestJSONSerializer.java
+++ b/src/test/java/net/sf/json/TestJSONSerializer.java
@@ -139,6 +139,15 @@ public class TestJSONSerializer extends TestCase {
assertEquals( beanB.getValue(), ((ValueBean) bb).getValue() );
}
+ public void testToJava_JSONObject_5() throws Exception {
+ try {
+ JSONObject.fromObject("/**");
+ fail("Should have thrown a JSONException");
+ } catch (JSONException expected) {
+ // ok
+ }
+ }
+
public void testToJava_JSONObject_and_reset() throws Exception {
String json = "{bool:true,integer:1,string:\"json\"}";
JSONObject jsonObject = JSONObject.fromObject( json );
--
2.43.0
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。