diff --git a/image/decoders/icon/nsIconURI.cpp b/image/decoders/icon/nsIconURI.cpp index e354a0f6cff0..49e5302082d5 100644 --- a/image/decoders/icon/nsIconURI.cpp +++ b/image/decoders/icon/nsIconURI.cpp @@ -144,6 +144,12 @@ nsMozIconURI::GetHasRef(bool* result) { return NS_OK; } +NS_IMETHODIMP +nsMozIconURI::GetHasUserPass(bool* result) { + *result = false; + return NS_OK; +} + NS_IMETHODIMP nsMozIconURI::GetHasQuery(bool* result) { *result = false; diff --git a/modules/libjar/nsJARURI.cpp b/modules/libjar/nsJARURI.cpp index 981e93b4ec9c..c55868cdfdf0 100644 --- a/modules/libjar/nsJARURI.cpp +++ b/modules/libjar/nsJARURI.cpp @@ -170,6 +170,11 @@ nsJARURI::GetDisplayHost(nsACString& aUnicodeHost) { NS_IMETHODIMP nsJARURI::GetHasRef(bool* result) { return mJAREntry->GetHasRef(result); } +NS_IMETHODIMP +nsJARURI::GetHasUserPass(bool* result) { + return mJAREntry->GetHasUserPass(result); +} + NS_IMETHODIMP nsJARURI::GetHasQuery(bool* result) { return mJAREntry->GetHasQuery(result); } diff --git a/netwerk/base/DefaultURI.cpp b/netwerk/base/DefaultURI.cpp index bfa0015e68da..0510305110d5 100644 --- a/netwerk/base/DefaultURI.cpp +++ b/netwerk/base/DefaultURI.cpp @@ -228,6 +228,11 @@ NS_IMETHODIMP DefaultURI::GetHasRef(bool* aHasRef) { return NS_OK; } +NS_IMETHODIMP DefaultURI::GetHasUserPass(bool* aHasUserPass) { + *aHasUserPass = !mURL->Username().IsEmpty() || !mURL->Password().IsEmpty(); + return NS_OK; +} + NS_IMETHODIMP DefaultURI::GetFilePath(nsACString& aFilePath) { aFilePath = mURL->FilePath(); return NS_OK; diff --git a/netwerk/base/nsIURI.idl b/netwerk/base/nsIURI.idl index 99ac05900881..993e0374a84a 100644 --- a/netwerk/base/nsIURI.idl +++ b/netwerk/base/nsIURI.idl @@ -250,6 +250,11 @@ interface nsIURI : nsISupports */ readonly attribute boolean hasRef; + /** + * Returns if there is user and pass in the URI. + */ + readonly attribute boolean hasUserPass; + /************************************************************************ * Additional attributes added for .query support: */ diff --git a/netwerk/base/nsSimpleURI.cpp b/netwerk/base/nsSimpleURI.cpp index 21cfc1302252..56e3300ffe14 100644 --- a/netwerk/base/nsSimpleURI.cpp +++ b/netwerk/base/nsSimpleURI.cpp @@ -264,6 +264,12 @@ nsSimpleURI::GetHasRef(bool* result) { return NS_OK; } +NS_IMETHODIMP +nsSimpleURI::GetHasUserPass(bool* result) { + *result = false; + return NS_OK; +} + nsresult nsSimpleURI::SetSpecInternal(const nsACString& aSpec, bool aStripWhitespace) { if (StaticPrefs::network_url_max_length() && diff --git a/netwerk/base/nsStandardURL.cpp b/netwerk/base/nsStandardURL.cpp index 65530fe06be8..dfc9b3c5cda7 100644 --- a/netwerk/base/nsStandardURL.cpp +++ b/netwerk/base/nsStandardURL.cpp @@ -2980,6 +2980,12 @@ nsStandardURL::GetHasRef(bool* result) { return NS_OK; } +NS_IMETHODIMP +nsStandardURL::GetHasUserPass(bool* result) { + *result = (mUsername.mLen >= 0) || (mPassword.mLen >= 0); + return NS_OK; +} + // result may contain unescaped UTF-8 characters NS_IMETHODIMP nsStandardURL::GetDirectory(nsACString& result) { diff --git a/netwerk/protocol/res/SubstitutingJARURI.h b/netwerk/protocol/res/SubstitutingJARURI.h index 12cc5f48890d..85976d490849 100644 --- a/netwerk/protocol/res/SubstitutingJARURI.h +++ b/netwerk/protocol/res/SubstitutingJARURI.h @@ -122,6 +122,10 @@ class SubstitutingJARURI : public nsIJARURI, NS_IMETHOD GetHasRef(bool* aHasRef) override { return !mSource ? NS_ERROR_NULL_POINTER : mSource->GetHasRef(aHasRef); } + NS_IMETHOD GetHasUserPass(bool* aHasUserPass) override { + return !mSource ? NS_ERROR_NULL_POINTER + : mSource->GetHasUserPass(aHasUserPass); + } NS_IMETHOD GetHasQuery(bool* aHasQuery) override { return !mSource ? NS_ERROR_NULL_POINTER : mSource->GetHasQuery(aHasQuery); } diff --git a/netwerk/test/unit/test_URIs.js b/netwerk/test/unit/test_URIs.js index 464ecd391369..98c24132f51a 100644 --- a/netwerk/test/unit/test_URIs.js +++ b/netwerk/test/unit/test_URIs.js @@ -493,10 +493,15 @@ function do_test_uri_basic(aTest) { do_check_property(aTest, URI, "password"); do_check_property(aTest, URI, "host"); do_check_property(aTest, URI, "specIgnoringRef"); - if ("hasRef" in aTest) { - do_info("testing hasref: " + aTest.hasRef + " vs " + URI.hasRef); - Assert.equal(aTest.hasRef, URI.hasRef); - } + + do_info("testing hasRef"); + Assert.equal(URI.hasRef, !!aTest.ref, "URI.hasRef is correct"); + do_info("testing hasUserPass"); + Assert.equal( + URI.hasUserPass, + !!aTest.username || !!aTest.password, + "URI.hasUserPass is correct" + ); } // Test that a given URI parses correctly when we add a given ref to the end diff --git a/netwerk/test/unit/test_defaultURI.js b/netwerk/test/unit/test_defaultURI.js index 92ac3042b307..36f6432db459 100644 --- a/netwerk/test/unit/test_defaultURI.js +++ b/netwerk/test/unit/test_defaultURI.js @@ -17,6 +17,7 @@ add_task(function test_getters() { equal(uri.userPass, "user:password"); equal(uri.username, "user"); equal(uri.password, "password"); + equal(uri.hasUserPass, true); equal(uri.hostPort, "hostname:123"); equal(uri.host, "hostname"); equal(uri.port, 123);