Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
halo
rockchip_libcore
Commits
b3503014
Commit
b3503014
authored
12 years ago
by
Brian Carlstrom
Committed by
Gerrit Code Review
12 years ago
Browse files
Options
Download
Plain Diff
Merge "Make sure URL.toURILenient throws the proper exception on trailing garbage escape"
parents
5088f4ce
bb1546d2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
1 deletion
+33
-1
luni/src/main/java/libcore/net/UriCodec.java
luni/src/main/java/libcore/net/UriCodec.java
+1
-1
luni/src/test/java/libcore/java/net/URLTest.java
luni/src/test/java/libcore/java/net/URLTest.java
+32
-0
No files found.
luni/src/main/java/libcore/net/UriCodec.java
View file @
b3503014
...
...
@@ -111,7 +111,7 @@ public abstract class UriCodec {
}
if
(
c
==
'%'
&&
isPartiallyEncoded
)
{
// this is an encoded 3-character sequence like "%20"
builder
.
append
(
s
,
i
,
i
+
3
);
builder
.
append
(
s
,
i
,
Math
.
min
(
i
+
3
,
s
.
length
())
);
i
+=
2
;
}
else
if
(
c
==
' '
)
{
builder
.
append
(
'+'
);
...
...
This diff is collapsed.
Click to expand it.
luni/src/test/java/libcore/java/net/URLTest.java
View file @
b3503014
...
...
@@ -19,6 +19,8 @@ package libcore.java.net;
import
java.net.Inet6Address
;
import
java.net.InetAddress
;
import
java.net.MalformedURLException
;
import
java.net.URISyntaxException
;
import
java.net.URI
;
import
java.net.URL
;
import
junit.framework.TestCase
;
import
libcore.util.SerializationTester
;
...
...
@@ -694,5 +696,35 @@ public final class URLTest extends TestCase {
assertEquals
(
"a_b.c.d.net"
,
url
.
getHost
());
}
// http://b/7369778
public
void
testToURILeniantThrowsURISyntaxExceptionWithPartialTrailingEscape
()
throws
Exception
{
// make sure if there a partial trailing escape that we don't throw the wrong exception
URL
[]
badUrls
=
new
URL
[]
{
new
URL
(
"http://example.com/?foo=%%bar"
),
new
URL
(
"http://example.com/?foo=%%bar%"
),
new
URL
(
"http://example.com/?foo=%%bar%2"
),
new
URL
(
"http://example.com/?foo=%%bar%%"
),
new
URL
(
"http://example.com/?foo=%%bar%%%"
),
new
URL
(
"http://example.com/?foo=%%bar%%%%"
),
};
for
(
URL
badUrl
:
badUrls
)
{
try
{
badUrl
.
toURILenient
();
fail
();
}
catch
(
URISyntaxException
expected
)
{
}
}
// make sure we properly handle an normal escape at the end of a string
String
[]
goodUrls
=
new
String
[]
{
"http://example.com/?foo=bar"
,
"http://example.com/?foo=bar%20"
,
};
for
(
String
goodUrl
:
goodUrls
)
{
assertEquals
(
new
URI
(
goodUrl
),
new
URL
(
goodUrl
).
toURILenient
());
}
}
// Adding a new test? Consider adding an equivalent test to URITest.java
}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment