зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1686808 - Don't use regex to parse URIs in WebExecutor. r=owlish
The harmless looking regex ``` uri.matches("(http|blob).*") ``` has a flaw: it will not accept URLs that contain a new line character. In that case GeckoWebExecutor errors out with "Unsupported URI scheme." when in reality that's not the problem at all. Since it has caused a bunch of headaches to the frontend already, let's just replace that regex with a plain `startsWith` which should work in all cases. Differential Revision: https://phabricator.services.mozilla.com/D102943
This commit is contained in:
Родитель
54cce40f63
Коммит
d0ea404038
|
@ -445,5 +445,22 @@ class WebExecutorTest {
|
|||
equalTo("Unsupported URI scheme: $truncated"))
|
||||
}
|
||||
}
|
||||
|
||||
val legal = listOf(
|
||||
"http://$TEST_ENDPOINT\n",
|
||||
"http://$TEST_ENDPOINT/🥲",
|
||||
"http://$TEST_ENDPOINT/abc"
|
||||
)
|
||||
|
||||
for (uri in legal) {
|
||||
try {
|
||||
fetch(WebRequest(uri))
|
||||
throw IllegalStateException("fetch() should have thrown")
|
||||
} catch (e: WebRequestError) {
|
||||
assertThat("Request should pass initial validation.",
|
||||
true,
|
||||
equalTo(true))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -141,7 +141,7 @@ public class GeckoWebExecutor {
|
|||
|
||||
final String uri = request.uri.toLowerCase(Locale.ROOT);
|
||||
// We don't need to fully validate the URI here, just a sanity check
|
||||
if (!uri.matches("(http|blob).*")) {
|
||||
if (!uri.startsWith("http") && !uri.startsWith("blob")) {
|
||||
throw new IllegalArgumentException("Unsupported URI scheme: " +
|
||||
(uri.length() > 10 ? uri.substring(0, 10) : uri));
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче