Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
phax committed Jun 7, 2023
1 parent 472cfee commit 8c70510
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
11 changes: 7 additions & 4 deletions ph-css/src/main/java/com/helger/css/parser/CSSParseHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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));
Expand Down
13 changes: 13 additions & 0 deletions ph-css/src/test/java/com/helger/css/parser/CSSParseHelperTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
}

0 comments on commit 8c70510

Please sign in to comment.