Skip to content

Fix: follow redirect unicode#646

Open
HaiqalAly wants to merge 6 commits intotower-rs:mainfrom
HaiqalAly:fix/follow-redirect-unicode
Open

Fix: follow redirect unicode#646
HaiqalAly wants to merge 6 commits intotower-rs:mainfrom
HaiqalAly:fix/follow-redirect-unicode

Conversation

@HaiqalAly
Copy link

Motivation

Hi there! I’m interested in helping out with #630.

I've swapped iri-string for url in the follow-redirect module as it seems to be the most robust way to handle non-ASCII characters in redirects. I'd appreciate any feedback on the approach.

Solution

  • Replaced iri-string with url crate in follow-redirect feature
  • Simplified resolve_uri() function implementation
  • Added tests for Unicode path and IDNA domain handling
  • Removed unused iri-string dependency

Testing

Added test_resolve_uri_unicode() that verifies:

  • Unicode characters in paths are percent-encoded correctly
  • International domain names are converted to punycode via IDNA

Copy link
Collaborator

@seanmonstar seanmonstar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

catch-panic = ["tracing", "futures-util/std", "dep:http-body", "dep:http-body-util"]
cors = []
follow-redirect = ["futures-util", "dep:http-body", "iri-string", "tower/util"]
follow-redirect = ["futures-util", "dep:http-body", "url", "tower/util"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
follow-redirect = ["futures-util", "dep:http-body", "url", "tower/util"]
follow-redirect = ["futures-util", "dep:http-body", "dep:url", "tower/util"]

Uri::try_from(uri).ok()
let base_url = Url::parse(&base.to_string()).ok()?;
let resolved = base_url.join(relative).ok()?;
resolved.as_str().parse().ok()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
resolved.as_str().parse().ok()
Uri::try_from(String::from(resolved)).ok()

(requires use std::convert::TryFrom; again)

parse incurs additional allocation.

@HaiqalAly
Copy link
Author

I've updated the PR with the suggested changes: switched url to a dep: dependency in Cargo.toml and moved to Uri::try_from to avoid the extra allocation. Ready for another review when you have a moment!

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.

3 participants