Issue #4033 - More tests for Lenient URIUtil behavior
Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
This commit is contained in:
parent
7da57151ed
commit
f47115c585
|
@ -646,6 +646,11 @@ public class StringUtil
|
|||
|
||||
public static boolean isHex(String str, int offset, int length)
|
||||
{
|
||||
if (offset + length > str.length())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = offset; i < (offset + length); i++)
|
||||
{
|
||||
char c = str.charAt(i);
|
||||
|
|
|
@ -513,9 +513,7 @@ public class URIUtil
|
|||
// we have a possible "%##" encoding
|
||||
if (StringUtil.isHex(path, i + 1, 2))
|
||||
{
|
||||
char c1 = path.charAt(i + 1);
|
||||
char c2 = path.charAt(i + 2);
|
||||
builder.append((byte)(0xff & (TypeUtil.convertHexDigit(c1) * 16 + TypeUtil.convertHexDigit(c2))));
|
||||
builder.append((byte)TypeUtil.parseInt(path, i + 1, 2, 16));
|
||||
i += 2;
|
||||
}
|
||||
else
|
||||
|
@ -1245,13 +1243,11 @@ public class URIUtil
|
|||
if (offset >= str.length())
|
||||
return -1;
|
||||
|
||||
char a1 = str.charAt(offset);
|
||||
char a2 = str.charAt(offset + 1);
|
||||
try
|
||||
if (StringUtil.isHex(str, offset, 2))
|
||||
{
|
||||
return TypeUtil.convertHexDigit(a1) * 16 + TypeUtil.convertHexDigit(a2);
|
||||
return TypeUtil.parseInt(str, offset, 2, 16);
|
||||
}
|
||||
catch (NumberFormatException e)
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -361,6 +361,8 @@ public class URIUtilTest
|
|||
|
||||
// encoded vs not-encode ("%" symbol is encoded as "%25")
|
||||
Arguments.of("/abc%25xyz", "/abc%xyz"),
|
||||
Arguments.of("/abc%25xy", "/abc%xy"),
|
||||
Arguments.of("/abc%25x", "/abc%x"),
|
||||
Arguments.of("/zzz%25", "/zzz%")
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue