Skip to content

Commit ae43713

Browse files
committed
---
yaml --- r: 153149 b: refs/heads/try2 c: ed47c47 h: refs/heads/master i: 153147: 6b82b7e v: v3
1 parent f705698 commit ae43713

File tree

2 files changed

+18
-37
lines changed

2 files changed

+18
-37
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: a9e82e145e61f4b9825b4622f78ea9364387ae70
8+
refs/heads/try2: ed47c479d73fd7b57d3b493e03c74e2932733163
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/liburl/lib.rs

Lines changed: 17 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -54,22 +54,16 @@ pub struct Url {
5454
pub host: String,
5555
/// A TCP port number, for example `8080`.
5656
pub port: Option<String>,
57-
/// The path component of a URL, for example `/foo/bar`.
58-
pub path: String,
59-
/// The query component of a URL.
60-
/// `vec!(("baz".to_string(), "qux".to_string()))` represents the fragment
61-
/// `baz=qux` in the above example.
62-
pub query: Query,
63-
/// The fragment component, such as `quz`. Not including the leading `#` character.
64-
pub fragment: Option<String>
57+
/// The path component of a URL, for example `/foo/bar?baz=qux#quz`.
58+
pub path: Path,
6559
}
6660

67-
#[deriving(Clone, PartialEq)]
61+
#[deriving(Clone, PartialEq, Eq)]
6862
pub struct Path {
6963
/// The path component of a URL, for example `/foo/bar`.
7064
pub path: String,
7165
/// The query component of a URL.
72-
/// `vec!(("baz".to_string(), "qux".to_string()))` represents the fragment
66+
/// `vec![("baz".to_string(), "qux".to_string())]` represents the fragment
7367
/// `baz=qux` in the above example.
7468
pub query: Query,
7569
/// The fragment component, such as `quz`. Not including the leading `#` character.
@@ -102,9 +96,7 @@ impl Url {
10296
user: user,
10397
host: host,
10498
port: port,
105-
path: path,
106-
query: query,
107-
fragment: fragment,
99+
path: Path::new(path, query, fragment)
108100
}
109101
}
110102

@@ -836,26 +828,15 @@ impl fmt::Show for Url {
836828
}
837829
}
838830

839-
try!(write!(f, "{}", self.path));
840-
841-
if !self.query.is_empty() {
842-
try!(write!(f, "?{}", query_to_str(&self.query)));
843-
}
844-
845-
match self.fragment {
846-
Some(ref fragment) => {
847-
write!(f, "#{}", encode_component(fragment.as_slice()))
848-
}
849-
None => Ok(()),
850-
}
831+
write!(f, "{}", self.path)
851832
}
852833
}
853834

854835
impl fmt::Show for Path {
855836
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
856837
try!(write!(f, "{}", self.path));
857838
if !self.query.is_empty() {
858-
try!(write!(f, "?{}", self.query))
839+
try!(write!(f, "?{}", query_to_str(&self.query)))
859840
}
860841

861842
match self.fragment {
@@ -981,9 +962,9 @@ mod tests {
981962
assert_eq!(&u.user, &Some(UserInfo::new("user".to_string(), Some("pass".to_string()))));
982963
assert_eq!(&u.host, &"rust-lang.org".to_string());
983964
assert_eq!(&u.port, &Some("8080".to_string()));
984-
assert_eq!(&u.path, &"/doc/~u".to_string());
985-
assert_eq!(&u.query, &vec!(("s".to_string(), "v".to_string())));
986-
assert_eq!(&u.fragment, &Some("something".to_string()));
965+
assert_eq!(&u.path.path, &"/doc/~u".to_string());
966+
assert_eq!(&u.path.query, &vec!(("s".to_string(), "v".to_string())));
967+
assert_eq!(&u.path.fragment, &Some("something".to_string()));
987968
}
988969

989970
#[test]
@@ -1002,7 +983,7 @@ mod tests {
1002983
let urlstr = "http://0.42.42.42/";
1003984
let url = from_str::<Url>(urlstr).unwrap();
1004985
assert!(url.host == "0.42.42.42".to_string());
1005-
assert!(url.path == "/".to_string());
986+
assert!(url.path.path == "/".to_string());
1006987
}
1007988

1008989
#[test]
@@ -1020,20 +1001,20 @@ mod tests {
10201001
assert_eq!(&url.host, &"host".to_string());
10211002
assert_eq!(&url.port, &Some("1234".to_string()));
10221003
// is empty path really correct? Other tests think so
1023-
assert_eq!(&url.path, &"".to_string());
1004+
assert_eq!(&url.path.path, &"".to_string());
10241005
let urlstr = "scheme://host:1234/";
10251006
let url = from_str::<Url>(urlstr).unwrap();
10261007
assert_eq!(&url.scheme, &"scheme".to_string());
10271008
assert_eq!(&url.host, &"host".to_string());
10281009
assert_eq!(&url.port, &Some("1234".to_string()));
1029-
assert_eq!(&url.path, &"/".to_string());
1010+
assert_eq!(&url.path.path, &"/".to_string());
10301011
}
10311012

10321013
#[test]
10331014
fn test_url_with_underscores() {
10341015
let urlstr = "http://dotcom.com/file_name.html";
10351016
let url = from_str::<Url>(urlstr).unwrap();
1036-
assert!(url.path == "/file_name.html".to_string());
1017+
assert!(url.path.path == "/file_name.html".to_string());
10371018
}
10381019

10391020
#[test]
@@ -1047,7 +1028,7 @@ mod tests {
10471028
fn test_url_with_dashes() {
10481029
let urlstr = "http://dotcom.com/file-name.html";
10491030
let url = from_str::<Url>(urlstr).unwrap();
1050-
assert!(url.path == "/file-name.html".to_string());
1031+
assert!(url.path.path == "/file-name.html".to_string());
10511032
}
10521033

10531034
#[test]
@@ -1133,8 +1114,8 @@ mod tests {
11331114
fn test_url_component_encoding() {
11341115
let url = "http://rust-lang.org/doc%20uments?ba%25d%20=%23%26%2B";
11351116
let u = from_str::<Url>(url).unwrap();
1136-
assert!(u.path == "/doc uments".to_string());
1137-
assert!(u.query == vec!(("ba%d ".to_string(), "#&+".to_string())));
1117+
assert!(u.path.path == "/doc uments".to_string());
1118+
assert!(u.path.query == vec!(("ba%d ".to_string(), "#&+".to_string())));
11381119
}
11391120

11401121
#[test]

0 commit comments

Comments
 (0)