Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

decode urls before reencoding with NSURL #39344

Closed
wants to merge 1 commit into from

Conversation

philIip
Copy link
Contributor

@philIip philIip commented Sep 8, 2023

Summary:
Changelog: [Internal]

in ios 17, NSURLs are encoded respecting RFC 3986 (https://www.ietf.org/rfc/rfc3986.txt) as opposed to RFC 1738/1808 before.

following this, NSURL's parsing algorithm has changed such that if they encounter a reserved character, such as [, the parser will percent encode all possible characters in the url, including %.

this causes trouble for urls that already have some encoding. for the string %22[], the new parsing algorithm will return the following:

RFC 1738/1808 -> %22%5B%5D
RFC 3986 -> %2522%5B%5D (invalid encoding)

the solution here is to decode all the percentified encodings in the input string, completely stripping it of the percent encodings, and then re-encoding it. thus, the string will transform as follows:

%22[] -> "[] -> %22%5B%5D

we probably don't need the OS check, but including it just to be safe.

Differential Revision: D49082077

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. p: Facebook Partner: Facebook Partner labels Sep 8, 2023
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D49082077

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D49082077

philIip added a commit to philIip/react-native that referenced this pull request Sep 8, 2023
Summary:

## Changelog:
[iOS][General] - URLs parsed by RCTConvert should be encoded respecting RFC 3986, 1738/1808

in ios 17, NSURLs are encoded respecting RFC 3986 (https://www.ietf.org/rfc/rfc3986.txt) as opposed to RFC 1738/1808 before.

following this, `NSURL`'s parsing algorithm has changed such that if they encounter a reserved character, such as `[`, the parser will percent encode all possible characters in the url, including `%`.

this causes trouble for urls that already have some encoding. for the string `%22[]`, the new parsing algorithm will return the following:

RFC 1738/1808 -> `%22%5B%5D`
RFC 3986 -> `%2522%5B%5D` (invalid encoding)

the solution here is to decode all the percentified encodings in the input string, completely stripping it of the percent encodings, and then re-encoding it. thus, the string will transform as follows:

`%22[]` -> `"[]` -> `%22%5B%5D`

we probably don't need the OS check, but including it just to be safe.

Reviewed By: yungsters

Differential Revision: D49082077
Summary:

## Changelog:
[iOS][General] - URLs parsed by RCTConvert should be encoded respecting RFC 3986, 1738/1808

in ios 17, NSURLs are encoded respecting RFC 3986 (https://www.ietf.org/rfc/rfc3986.txt) as opposed to RFC 1738/1808 before.

following this, `NSURL`'s parsing algorithm has changed such that if they encounter a reserved character, such as `[`, the parser will percent encode all possible characters in the url, including `%`.

this causes trouble for urls that already have some encoding. for the string `%22[]`, the new parsing algorithm will return the following:

RFC 1738/1808 -> `%22%5B%5D`
RFC 3986 -> `%2522%5B%5D` (invalid encoding)

the solution here is to decode all the percentified encodings in the input string, completely stripping it of the percent encodings, and then re-encoding it. thus, the string will transform as follows:

`%22[]` -> `"[]` -> `%22%5B%5D`

we probably don't need the OS check, but including it just to be safe.

Reviewed By: yungsters

Differential Revision: D49082077
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D49082077

@github-actions
Copy link

github-actions bot commented Sep 8, 2023

This pull request was successfully merged by @philIip in 9841bd8.

When will my fix make it into a release? | Upcoming Releases

@github-actions github-actions bot added the Merged This PR has been merged. label Sep 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported Merged This PR has been merged. p: Facebook Partner: Facebook Partner
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants