Bug 1411932 - rusturl_get_path should not depend on cannot-be-a-base r=baku draft
authorValentin Gosu <valentin.gosu@gmail.com>
Thu, 26 Oct 2017 13:47:56 +0200
changeset 686797 a18072d754958b376356dd12b595b4ad1fc7500f
parent 686348 30c5e28c61adace06cd49ca216108a277e37d58d
child 737468 f5aa877664c825c51755f6b589ffae09ee1bb30f
push id86289
push uservalentin.gosu@gmail.com
push dateThu, 26 Oct 2017 12:02:54 +0000
reviewersbaku
bugs1411932
milestone58.0a1
Bug 1411932 - rusturl_get_path should not depend on cannot-be-a-base r=baku MozReview-Commit-ID: 7iwBooZWNxW
netwerk/base/rust-url-capi/src/lib.rs
netwerk/test/gtest/TestMozURL.cpp
--- a/netwerk/base/rust-url-capi/src/lib.rs
+++ b/netwerk/base/rust-url-capi/src/lib.rs
@@ -165,37 +165,29 @@ pub extern "C" fn rusturl_get_port(urlpt
 #[no_mangle]
 pub extern "C" fn rusturl_get_filepath(urlptr: Option<&Url>, cont: &mut nsACString) -> nsresult {
   let url = if let Some(url) = urlptr {
     url
   } else {
     return NS_ERROR_INVALID_ARG;
   };
 
-  if url.cannot_be_a_base() {
-      cont.assign("");
-  } else {
-      cont.assign(&url[Position::BeforePath..Position::AfterPath]);
-  }
+  cont.assign(&url.path());
   NS_OK
 }
 
 #[no_mangle]
 pub extern "C" fn rusturl_get_path(urlptr: Option<&Url>, cont: &mut nsACString) -> nsresult {
   let url = if let Some(url) = urlptr {
     url
   } else {
     return NS_ERROR_INVALID_ARG;
   };
 
-  if url.cannot_be_a_base() {
-      cont.assign("");
-  } else {
-      cont.assign(&url[Position::BeforePath..]);
-  }
+  cont.assign(&url[Position::BeforePath..]);
   NS_OK
 }
 
 #[no_mangle]
 pub extern "C" fn rusturl_get_query(urlptr: Option<&Url>, cont: &mut nsACString) -> nsresult {
   let url = if let Some(url) = urlptr {
     url
   } else {
--- a/netwerk/test/gtest/TestMozURL.cpp
+++ b/netwerk/test/gtest/TestMozURL.cpp
@@ -114,8 +114,25 @@ TEST(TestMozURL, InitWithBase)
 
   RefPtr<MozURL> url2;
   ASSERT_EQ(MozURL::Init(getter_AddRefs(url2), NS_LITERAL_CSTRING("c.png"),
                          url), NS_OK);
 
   ASSERT_EQ(url2->GetSpec(out), NS_OK);
   ASSERT_TRUE(out.EqualsLiteral("https://example.net/a/c.png"));
 }
+
+TEST(TestMozURL, Path)
+{
+  nsAutoCString href("about:blank");
+  RefPtr<MozURL> url;
+  ASSERT_EQ(MozURL::Init(getter_AddRefs(url), href), NS_OK);
+  nsAutoCString out;
+
+  ASSERT_EQ(url->GetSpec(out), NS_OK);
+  ASSERT_TRUE(out.EqualsLiteral("about:blank"));
+
+  ASSERT_EQ(url->GetScheme(out), NS_OK);
+  ASSERT_TRUE(out.EqualsLiteral("about"));
+
+  ASSERT_EQ(url->GetFilePath(out), NS_OK);
+  ASSERT_TRUE(out.EqualsLiteral("blank"));
+}