File tree Expand file tree Collapse file tree
main/java/org/apache/xmlbeans/impl/util Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -558,7 +558,7 @@ private static String trimInitialPlus(String xml) {
558558
559559 private static String trimTrailingZeros (String xsd_decimal ) {
560560 final int last_char_idx = xsd_decimal .length () - 1 ;
561- if (xsd_decimal .charAt (last_char_idx ) == '0' ) {
561+ if (last_char_idx >= 0 && xsd_decimal .charAt (last_char_idx ) == '0' ) {
562562 final int last_point = xsd_decimal .lastIndexOf ('.' );
563563 if (last_point >= 0 ) {
564564 //find last trailing zero
Original file line number Diff line number Diff line change @@ -76,4 +76,17 @@ void lexFloatAcceptsValidValues() {
7676 assertEquals (Float .POSITIVE_INFINITY , XsTypeConverter .lexFloat ("INF" ));
7777 assertEquals (Float .NEGATIVE_INFINITY , XsTypeConverter .lexFloat ("-INF" ));
7878 }
79+
80+ @ Test
81+ void lexDecimalRejectsEmptyString () {
82+ // an empty value used to read charAt(-1) in trimTrailingZeros and
83+ // throw StringIndexOutOfBoundsException instead of NumberFormatException.
84+ assertThrows (NumberFormatException .class , () -> XsTypeConverter .lexDecimal ("" ));
85+ }
86+
87+ @ Test
88+ void lexDecimalTrimsTrailingZeros () {
89+ assertEquals (0 , new java .math .BigDecimal ("1.5" ).compareTo (XsTypeConverter .lexDecimal ("1.500" )));
90+ assertEquals (0 , new java .math .BigDecimal ("12" ).compareTo (XsTypeConverter .lexDecimal ("12.000" )));
91+ }
7992}
You can’t perform that action at this time.
0 commit comments