Bug 1172697 - URLs containing !// in the query or hash should not be handled as packaged app resources r=mcmanus

This commit is contained in:
Valentin Gosu 2015-06-09 02:20:02 +03:00
parent 2288418a7a
commit 76297166d8
2 changed files with 25 additions and 1 deletions

View File

@ -4793,7 +4793,10 @@ nsHttpChannel::AsyncOpen(nsIStreamListener *listener, nsISupports *context)
MOZ_ASSERT(NS_IsMainThread());
if (gHttpHandler->PackagedAppsEnabled()) {
nsAutoCString path;
mURI->GetPath(path);
nsCOMPtr<nsIURL> url(do_QueryInterface(mURI));
if (url) {
url->GetFilePath(path);
}
mIsPackagedAppResource = path.Find(PACKAGED_APP_TOKEN) != kNotFound;
}

View File

@ -100,6 +100,12 @@ function contentHandler(metadata, response)
response.bodyOutputStream.write(body, body.length);
}
function regularContentHandler(metadata, response)
{
var body = "response";
response.bodyOutputStream.write(body, body.length);
}
var httpserver = null;
var originalPref = false;
@ -108,6 +114,7 @@ function run_test()
// setup test
httpserver = new HttpServer();
httpserver.registerPathHandler("/package", contentHandler);
httpserver.registerPathHandler("/regular", regularContentHandler);
httpserver.start(-1);
// Enable the feature and save the original pref value
@ -116,6 +123,7 @@ function run_test()
do_register_cleanup(reset_pref);
add_test(test_channel);
add_test(test_channel_uris);
// run tests
run_next_test();
@ -132,6 +140,19 @@ function test_channel() {
}), null);
}
function test_channel_uris() {
// A `!//` in the query or ref should not be handled as a packaged app resource
var channel = make_channel(uri+"/regular?bla!//bla#bla!//bla");
channel.asyncOpen(new ChannelListener(check_regular_response, null), null);
}
function check_regular_response(request, buffer) {
request.QueryInterface(Components.interfaces.nsIHttpChannel);
do_check_eq(request.responseStatus, 200);
do_check_eq(buffer, "response");
run_next_test();
}
function reset_pref() {
// Set the pref to its original value
Services.prefs.setBoolPref("network.http.enable-packaged-apps", originalPref);