diff --git a/ph-css/src/main/java/com/helger/css/parser/CSSParseHelper.java b/ph-css/src/main/java/com/helger/css/parser/CSSParseHelper.java index 18a990b7..e9326f60 100644 --- a/ph-css/src/main/java/com/helger/css/parser/CSSParseHelper.java +++ b/ph-css/src/main/java/com/helger/css/parser/CSSParseHelper.java @@ -126,7 +126,7 @@ public static String unescapeURL (@Nonnull final String sEscapedURL) { int nCodePoint = 0; int nHexCount = 0; - while (nHexCount <= 6) + while (nHexCount <= 6 && nCharIndex < nSrcLen) { final char cNext = sEscapedURL.charAt (nCharIndex); if (_isHexChar (cNext)) @@ -142,9 +142,12 @@ public static String unescapeURL (@Nonnull final String sEscapedURL) if (nHexCount > 0) { // Check for a trailing whitespace and evtl. skip it - final char cNext = sEscapedURL.charAt (nCharIndex); - if (_isWhitespace (cNext)) - nCharIndex++; + if (nCharIndex < nSrcLen) + { + final char cNext = sEscapedURL.charAt (nCharIndex); + if (_isWhitespace (cNext)) + nCharIndex++; + } if (nCodePoint > '\uFFFF') aSB.append (Character.toChars (nCodePoint)); diff --git a/ph-css/src/test/java/com/helger/css/parser/CSSParseHelperTest.java b/ph-css/src/test/java/com/helger/css/parser/CSSParseHelperTest.java index 1b68097b..72dd32f4 100644 --- a/ph-css/src/test/java/com/helger/css/parser/CSSParseHelperTest.java +++ b/ph-css/src/test/java/com/helger/css/parser/CSSParseHelperTest.java @@ -66,5 +66,18 @@ public void testUnescapeCSSURL () assertEquals ("/home/data/image.png", CSSParseHelper.unescapeURL ("\\2fhome\\2f data\\2fimage.png")); assertEquals ("/home /data /image.png", CSSParseHelper.unescapeURL ("\\2fhome \\2f data \\2f image.png")); assertEquals ("/home /data /image.png", CSSParseHelper.unescapeURL ("\\2fhome \\2f data \\2fimage.png")); + assertEquals ("A", CSSParseHelper.unescapeURL ("\\41")); + assertEquals ("A", CSSParseHelper.unescapeURL ("\\41 ")); + assertEquals ("A ", CSSParseHelper.unescapeURL ("\\41 ")); + assertEquals ("AZ", CSSParseHelper.unescapeURL ("\\41Z")); + assertEquals ("AZ", CSSParseHelper.unescapeURL ("\\41 Z")); + assertEquals ("AZ", CSSParseHelper.unescapeURL ("\\041Z")); + assertEquals ("AZ", CSSParseHelper.unescapeURL ("\\041 Z")); + assertEquals ("AZ", CSSParseHelper.unescapeURL ("\\0041Z")); + assertEquals ("AZ", CSSParseHelper.unescapeURL ("\\0041 Z")); + assertEquals ("AZ", CSSParseHelper.unescapeURL ("\\00041Z")); + assertEquals ("AZ", CSSParseHelper.unescapeURL ("\\00041 Z")); + assertEquals ("AZ", CSSParseHelper.unescapeURL ("\\000041Z")); + assertEquals ("AZ", CSSParseHelper.unescapeURL ("\\000041 Z")); } }