Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Work aroundparse_url() bug (bis)#58836

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

nicolas-grekas
Copy link
Member

@nicolas-grekasnicolas-grekas commentedNov 12, 2024
edited
Loading

QA
Branch?5.4
Bug fix?yes
New feature?no
Deprecations?no
Issues#58313
LicenseMIT

This PR is a follow up of#58218

parse_url behaves incorrectly when parsing some URLs that don't contain? or#.
This PR ensures that one of those chars is always found when calling the function.

@carsonbotcarsonbot added this to the5.4 milestoneNov 12, 2024
@nicolas-grekasnicolas-grekasforce-pushed theparse-url-bug-bis branch 2 times, most recently from6c067aa to5e3509bCompareNovember 12, 2024 11:05
@OskarStarkOskarStark changed the titleWork around parse_url() bug (bis)Work aroundparse_url() bug (bis)Nov 12, 2024
@nicolas-grekasnicolas-grekasforce-pushed theparse-url-bug-bis branch 2 times, most recently from0cbc0dd to6cd3610CompareNovember 13, 2024 09:54
@nicolas-grekas
Copy link
MemberAuthor

PR ready. I figured out a way to fix#58313

$scheme = $parts['scheme'] ?? null;
$host = $parts['host'] ?? null;

if (!$scheme && $host && !str_starts_with($url, '//')) {
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I wondered if we could add the same logic to Request::create() but we have a test case that ensureRequest::create("test.com:80") is parsed as host+port (which is not how the URL spec would parse it)

@@ -416,7 +417,7 @@ private static function createRedirectResolver(array $options, string $host, ?ar

[$host, $port] = self::parseHostPort($url, $info);

if (false !== (parse_url($location.'#', \PHP_URL_HOST) ?? false)) {
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

stop using parse_url on user-input

$options['max_redirects'] = curl_getinfo($ch, \CURLINFO_REDIRECT_COUNT);
curl_setopt($ch, \CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, \CURLOPT_MAXREDIRS, $options['max_redirects']);
} else {
$url = parse_url($location ?? ':');
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

stop using parse_url on user-input here also

unset($server['HTTPS']);
$server['SERVER_PORT'] = 80;
} else {
throw new BadRequestException('Invalid URI: http(s) scheme expected.');
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

looks like a missing check here,Request::create('random-scheme:foo') cannot give port 80

@nicolas-grekasnicolas-grekas merged commit4b8695c intosymfony:5.4Nov 13, 2024
10 of 12 checks passed
@nicolas-grekasnicolas-grekas deleted the parse-url-bug-bis branchNovember 13, 2024 16:29
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@xabbuhxabbuhxabbuh left review comments

Assignees
No one assigned
Projects
None yet
Milestone
5.4
Development

Successfully merging this pull request may close these issues.

3 participants
@nicolas-grekas@xabbuh@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp