Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Bug 1426501 - Change nsIURIMutator to call set spec on cloned URI if …
Browse files Browse the repository at this point in the history
…available r=mayhemer

Calling SetSpec on an nsIURI object doesn't reinitialize the object, meaning
it's not equivalent with creating a new URI with the same spec. While this
might be counter-intuitive we want to preserve existing behaviour for
the moment.
This change makes BaseURIMutator::InitFromSpec call SetSpec on the existing
cloned URI if available. Otherwise it creates a new one.

MozReview-Commit-ID: LuHVRhBItiP
  • Loading branch information
valenting committed Jan 8, 2018
1 parent 522dcd8 commit 6b6c980
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
12 changes: 10 additions & 2 deletions netwerk/base/nsIURIMutator.idl
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,16 @@ protected:

MOZ_MUST_USE nsresult InitFromSpec(const nsACString& aSpec)
{
RefPtr<T> uri = new T();
nsresult rv = uri->SetSpec(aSpec);
nsresult rv = NS_OK;
RefPtr<T> uri;
if (mURI) {
// This only works because all other Init methods create a new object
mURI.swap(uri);
} else {
uri = new T();
}

rv = uri->SetSpec(aSpec);
if (NS_FAILED(rv)) {
return rv;
}
Expand Down
7 changes: 5 additions & 2 deletions netwerk/test/unit/test_URIs.js
Original file line number Diff line number Diff line change
Expand Up @@ -485,8 +485,11 @@ function do_test_mutate_ref(aTest, aSuffix) {
var specWithSuffix = aTest.spec + aSuffix;
do_info("testing that setting spec to " +
specWithSuffix + " and then clearing ref does what we expect");
testURI.spec = specWithSuffix;
testURI.ref = "";

testURI = testURI.mutate()
.setSpec(specWithSuffix)
.setRef("")
.finalize();
do_check_uri_eq(testURI, refURIWithoutSuffix);
do_check_uri_eqExceptRef(testURI, refURIWithSuffix);

Expand Down
6 changes: 4 additions & 2 deletions netwerk/test/unit/test_URIs2.js
Original file line number Diff line number Diff line change
Expand Up @@ -587,8 +587,10 @@ function do_test_mutate_ref(aTest, aSuffix) {
var specWithSuffix = aTest.spec + aSuffix;
do_info("testing that setting spec to " +
specWithSuffix + " and then clearing ref does what we expect");
testURI.spec = specWithSuffix;
testURI.ref = "";
testURI = testURI.mutate()
.setSpec(specWithSuffix)
.setRef("")
.finalize();
do_check_uri_eq(testURI, refURIWithoutSuffix);
do_check_uri_eqExceptRef(testURI, refURIWithSuffix);

Expand Down

0 comments on commit 6b6c980

Please sign in to comment.