Skip to content

Add Url::path_segments_mut, fix #188 - #194

Merged
bors-servo merged 3 commits into
masterfrom
path-segments
May 3, 2016
Merged

bors-servo merged 3 commits into
masterfrom
path-segments

Conversation

@SimonSapin

@SimonSapin SimonSapin commented May 2, 2016 •

Copy link
Copy Markdown
Member

@sfackler @maximih @jgillich How does this look? Would these new API help for your use cases? Can they be improved?

@nox, please review but don’t land yet.


This change is Reviewable

@sfackler

sfackler commented May 2, 2016

Copy link
Copy Markdown
Contributor

This looks great!

@mhristache

Copy link
Copy Markdown
Contributor

I think it looks good even though I find this a bit unexpected:

extern crate url;

fn main() {

    let mut my_url = url::Url::parse("http://this/is/a").unwrap();

    let new_url = my_url.join("./test").unwrap();
    println!("{}", new_url.as_str());

    my_url.path_segments_mut().unwrap().push("./test");
    println!("{}", my_url.as_str());
}

Which prints:

http://this/is/test
http://this/is/a/.%2Ftest

where I was expecting http://this/is/a/test so that it's consistent with join() implementation.

Anyhow, it's not a big deal as I can fi it by using my_url.path_segments_mut().unwrap().push("test")

So I am happy with the implementation. Thanks for your effort

@SimonSapin

Copy link
Copy Markdown
Member Author

It is by design that PathSegmentsMut::push escapes slashes and does not interpret . or .. specially: it adds exactly one segment, whatever the characters in that segment. The point is not to do the same as join, you can use join for that.

Actually, I wonder what push(".") or push("..") should do. With the code is it currently is, Url::parse(url.as_str()).unwrap() == url would not hold, since . and .. segments are normalized during parsing. @nox, what do you think?

@nox

nox commented May 3, 2016

Copy link
Copy Markdown
Contributor

@nox, what do you think?

That's a good question. Maybe it should panic on . and ..?

Btw, r=me for the rest.

@SimonSapin

Copy link
Copy Markdown
Member Author

I've added a commit to ignore . and make .. behave like pop()

@SimonSapin

Copy link
Copy Markdown
Member Author

@bors-servo r=nox

(IRC)

@bors-servo

Copy link
Copy Markdown
Contributor

📌 Commit e66486a has been approved by nox

@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Testing commit e66486a with merge d91d175...

bors-servo pushed a commit that referenced this pull request May 3, 2016
Add Url::path_segments_mut, fix #188

@sfackler @maximih @jgillich How does this look? Would these new API help for your use cases? Can they be improved?

@nox, please review and but don’t land yet.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/rust-url/194)
<!-- Reviewable:end -->
@bors-servo

Copy link
Copy Markdown
Contributor

☀️ Test successful - travis

@bors-servo
bors-servo merged commit e66486a into master May 3, 2016
@SimonSapin
SimonSapin deleted the path-segments branch May 3, 2016 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants