@@ -1468,6 +1468,42 @@ public void testInvalidHexEntityThrowsJSONException() {
14681468 XML .toJSONObject (xmlStr );
14691469 }
14701470
1471+ /**
1472+ * Tests that out-of-range hex entities throw JSONException rather than an uncaught runtime exception.
1473+ */
1474+ @ Test (expected = JSONException .class )
1475+ public void testOutOfRangeHexEntityThrowsJSONException () {
1476+ String xmlStr = "<a>�</a>" ;
1477+ XML .toJSONObject (xmlStr );
1478+ }
1479+
1480+ /**
1481+ * Tests that out-of-range decimal entities throw JSONException rather than an uncaught runtime exception.
1482+ */
1483+ @ Test (expected = JSONException .class )
1484+ public void testOutOfRangeDecimalEntityThrowsJSONException () {
1485+ String xmlStr = "<a>�</a>" ;
1486+ XML .toJSONObject (xmlStr );
1487+ }
1488+
1489+ /**
1490+ * Tests that surrogate code point entities throw JSONException.
1491+ */
1492+ @ Test (expected = JSONException .class )
1493+ public void testSurrogateHexEntityThrowsJSONException () {
1494+ String xmlStr = "<a>�</a>" ;
1495+ XML .toJSONObject (xmlStr );
1496+ }
1497+
1498+ /**
1499+ * Tests that out-of-range numeric entities in attribute values throw JSONException.
1500+ */
1501+ @ Test (expected = JSONException .class )
1502+ public void testOutOfRangeHexEntityInAttributeThrowsJSONException () {
1503+ String xmlStr = "<a b=\" �\" />" ;
1504+ XML .toJSONObject (xmlStr );
1505+ }
1506+
14711507 /**
14721508 * Tests that valid decimal numeric entity A works correctly.
14731509 * Should decode to character 'A'.
0 commit comments