Bug 1251229 P1 Strip fragment from request URL when creating FetchEvent. r=ehsan
authorBen Kelly <ben@wanderview.com>
Mon, 29 Feb 2016 13:21:19 -0500
changeset 286084 982cf5b26ae109823c22405daefc2cc83726f254
parent 286083 3078ede85d93d149bd4c3d13fe2815b5db812902
child 286085 d6df13193dc8109b63cd24f46ed2a908c6e8ad9b
push id72630
push userbkelly@mozilla.com
push dateMon, 29 Feb 2016 18:21:29 +0000
treeherdermozilla-inbound@d6df13193dc8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs1251229
milestone47.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1251229 P1 Strip fragment from request URL when creating FetchEvent. r=ehsan
dom/fetch/InternalRequest.h
dom/workers/ServiceWorkerPrivate.cpp
--- a/dom/fetch/InternalRequest.h
+++ b/dom/fetch/InternalRequest.h
@@ -136,16 +136,22 @@ public:
     , mPreserveContentCodings(false)
       // FIXME See the above comment in the default constructor.
     , mSameOriginDataURL(true)
     , mSkipServiceWorker(false)
     , mSynchronous(false)
     , mUnsafeRequest(false)
     , mUseURLCredentials(false)
   {
+    // Normally we strip the fragment from the URL in Request::Constructor.
+    // If internal code is directly constructing this object they must
+    // strip the fragment first.  Since these should be well formed URLs we
+    // can use a simple check for a fragment here.  The full parser is
+    // difficult to use off the main thread.
+    MOZ_ASSERT(mURL.Find(NS_LITERAL_CSTRING("#")) == kNotFound);
   }
 
   already_AddRefed<InternalRequest> Clone();
 
   void
   GetMethod(nsCString& aMethod) const
   {
     aMethod.Assign(mMethod);
--- a/dom/workers/ServiceWorkerPrivate.cpp
+++ b/dom/workers/ServiceWorkerPrivate.cpp
@@ -1039,17 +1039,25 @@ public:
     nsCOMPtr<nsIChannel> channel;
     nsresult rv = mInterceptedChannel->GetChannel(getter_AddRefs(channel));
     NS_ENSURE_SUCCESS(rv, rv);
 
     nsCOMPtr<nsIURI> uri;
     rv = mInterceptedChannel->GetSecureUpgradedChannelURI(getter_AddRefs(uri));
     NS_ENSURE_SUCCESS(rv, rv);
 
-    rv = uri->GetSpec(mSpec);
+    // Normally we rely on the Request constructor to strip the fragment, but
+    // when creating the FetchEvent we bypass the constructor.  So strip the
+    // fragment manually here instead.  We can't do it later when we create
+    // the Request because that code executes off the main thread.
+    nsCOMPtr<nsIURI> uriNoFragment;
+    rv = uri->CloneIgnoringRef(getter_AddRefs(uriNoFragment));
+    NS_ENSURE_SUCCESS(rv, rv);
+
+    rv = uriNoFragment->GetSpec(mSpec);
     NS_ENSURE_SUCCESS(rv, rv);
 
     uint32_t loadFlags;
     rv = channel->GetLoadFlags(&loadFlags);
     NS_ENSURE_SUCCESS(rv, rv);
 
     nsCOMPtr<nsILoadInfo> loadInfo;
     rv = channel->GetLoadInfo(getter_AddRefs(loadInfo));