[
https://issues.apache.org/jira/browse/GROOVY-12168?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18096921#comment-18096921
]
ASF GitHub Bot commented on GROOVY-12168:
-----------------------------------------
Copilot commented on code in PR #2715:
URL: https://github.com/apache/groovy/pull/2715#discussion_r3599488709
##########
subprojects/groovy-json/src/test/groovy/groovy/json/JsonSlurperMalformedNumberTest.groovy:
##########
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package groovy.json
+
+import org.junit.jupiter.api.Test
+
+import static groovy.test.GroovyAssert.shouldFail
+
+/**
+ * A leading digit or minus makes the parser enter number decoding, but a
malformed exponent or a
+ * lone sign/point is only rejected when the token is finally handed to {@code
new BigDecimal(...)}.
+ * The overlay parsers already wrap that {@link NumberFormatException} in a
{@link JsonException}
+ * (see {@code NumberValue.bigDecimalValue}), but the default CHAR_BUFFER path
+ * ({@code CharScanner.parseJsonNumber}) and the CHARACTER_SOURCE path
+ * ({@code JsonParserUsingCharacterSource.decodeNumber}) let it escape raw, so
a caller guarding
+ * untrusted input with {@code catch (JsonException)} would not catch it.
Review Comment:
The class Javadoc describes the CHAR_BUFFER and CHARACTER_SOURCE paths as
currently letting NumberFormatException escape. After this PR’s changes, that
should be phrased in the past tense so the documentation matches the new
behavior.
> Improve exception handling consistency for numbers during JSON parsing
> ----------------------------------------------------------------------
>
> Key: GROOVY-12168
> URL: https://issues.apache.org/jira/browse/GROOVY-12168
> Project: Groovy
> Issue Type: Improvement
> Reporter: Paul King
> Priority: Major
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)