diff --git a/extensions/cookie/nsPermissionManager.cpp b/extensions/cookie/nsPermissionManager.cpp index 2167506e983..bf871a626fa 100644 --- a/extensions/cookie/nsPermissionManager.cpp +++ b/extensions/cookie/nsPermissionManager.cpp @@ -94,8 +94,12 @@ GetPrincipal(const nsACString& aHost, uint32_t aAppId, bool aIsInBrowserElement, if (NS_FAILED(rv)) { // NOTE: most callers will end up here because we don't append "http://" for // hosts. It's fine to arbitrary use "http://" because, for those entries, - // we will actually just use the host. - rv = NS_NewURI(getter_AddRefs(uri), NS_LITERAL_CSTRING("http://") + aHost); + // we will actually just use the host. If we end up here, but the host looks + // like an email address, we use mailto: instead. + nsCString scheme = NS_LITERAL_CSTRING( + (aHost.FindChar('@') == -1) ? "http://" : "mailto:"); + + rv = NS_NewURI(getter_AddRefs(uri), scheme + aHost); NS_ENSURE_SUCCESS(rv, rv); } diff --git a/extensions/cookie/test/unit/test_permmanager_mailto.js b/extensions/cookie/test/unit/test_permmanager_mailto.js index 55499d63c38..2c05fefed23 100644 --- a/extensions/cookie/test/unit/test_permmanager_mailto.js +++ b/extensions/cookie/test/unit/test_permmanager_mailto.js @@ -15,13 +15,16 @@ function run_test() { Services.perms.add(uri, kType, kCapability); do_check_true(permission_exists(kTestAddr, kType, kCapability)); - Services.perms.removeAll(); + // remove the permission, and make sure it was removed + Services.perms.remove(kTestAddr, kType); + do_check_false(permission_exists(kTestAddr, kType, kCapability)); uri = Services.io.newURI("mailto:" + kTestAddr, null, null); Services.perms.add(uri, kType, kCapability); do_check_true(permission_exists(kTestAddr, kType, kCapability)); - Services.perms.removeAll(); + Services.perms.remove(kTestAddr, kType); + do_check_false(permission_exists(kTestAddr, kType, kCapability)); } function permission_exists(aHost, aType, aCapability) {