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

[Validator] support protocolless urls validation#24308

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

@MyDigitalLife
Copy link
Contributor

@MyDigitalLifeMyDigitalLife commentedSep 24, 2017
edited by nicolas-grekas
Loading

QA
Branch?3.4
Bug fix?no
New feature?yes
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets#24287
LicenseMIT

As specified in issue#24287 URL's starting with no protocol but with just// are valid URL's and should be accepted by the validator. This pull request fixes the regex used to validate URL's.

@nicolas-grekas
Copy link
Member

I'm not sure we can do this change as is: protocol-relative URLs have only a relative meaning.
What if I want to validate that an URL is not-relative, as this validation rule used to provide?
In a Web form, many won't want to accept protocol-relative URLs, isn't it?

@nicolas-grekasnicolas-grekas added this to the2.8 milestoneSep 24, 2017
@MyDigitalLife
Copy link
ContributorAuthor

@nicolas-grekas Good point. I see 2 possible ways to fix this:

  1. Create a RelativeUrlValidator class
  2. Add a option to the current validator that can enable or disable the check for relative URL's

I think option 2 is the better one. And to not break BC it should probably by default not allow relative URL's.

@nicolas-grekas
Copy link
Member

Let's go for option 2, with a default that doesn't change the behavior for sure.
Should be submitted as a new feature, so against 3.4.

MyDigitalLife, ogizanagi, linaori, and supercid reacted with thumbs up emoji

@MyDigitalLifeMyDigitalLife changed the base branch from2.8 to3.4September 24, 2017 15:07
@fabpot
Copy link
Member

Can you rebase this PR to get rid of the merge commit? Thanks.

publicfunctiontestValidRelativeUrl($url)
{
$constraint =newUrl(array(
'relativeProtocol' =>true,
Copy link
Contributor

Choose a reason for hiding this comment

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

should also test absolute urls are still valid

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

The test has bothgetValidRelativeUrls andgetValidUrls as a data provider. That covers both absolute and relative URL's. Or am I missing something?

Copy link
Contributor

Choose a reason for hiding this comment

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

@MyDigitalLife nice :) didnt noticed that.

MyDigitalLife reacted with thumbs up emoji

publicfunctiongetInvalidRelativeUrls()
{
returnarray(

Choose a reason for hiding this comment

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

Any reason why we are not using[] instead ofarray

Copy link
Member

@javiereguiluzjaviereguiluzSep 25, 2017
edited
Loading

Choose a reason for hiding this comment

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

It's becauseSymfony coding standards. We can't easily change the existing code fromarray() to[] ... so using[] only for the new code would be inconsistent and that's why we usearray() everywhere.

MyDigitalLife and supercid reacted with thumbs up emoji
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

This started as a patch for 2.8 so I needed to use thearray keyword to not break code in PHP 5.3 seeing this is supported with Symfony 2.x. I definitely prefer the brackets and could changes it.

@MyDigitalLife
Copy link
ContributorAuthor

@fabpot The PR has been rebased.

}

$pattern =sprintf(static::PATTERN,implode('|',$constraint->protocols));
$protocolPattern ='(%s):';
Copy link
Contributor

Choose a reason for hiding this comment

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

non-capturing, i.e.(?:%s):? Might be patched in 2.7 for groups currently inPATTERN. Not a real blocker though.

$pattern =sprintf(static::PATTERN,implode('|',$constraint->protocols));
$protocolPattern ='(%s):';
if ($constraint->relativeProtocol) {
$protocolPattern ='((%s):)?';
Copy link
Contributor

Choose a reason for hiding this comment

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

What about(?:'.$protocolPattern.')? to reuse previous pattern. Also no real reason for capturing here.

@nicolas-grekas
Copy link
Member

Moving to 4.1 as 3.4 is in beta, thus closed for new feats.

@nicolas-grekasnicolas-grekas modified the milestones:2.8,4.1Oct 24, 2017
@Simperfit
Copy link
Contributor

Could you please rebase against master ?

@nicolas-grekasnicolas-grekas changed the title[Validator] Updated Validator to support protocolless urls.[Validator] support protocolless urls validationFeb 14, 2018
@nicolas-grekasnicolas-grekas changed the base branch from3.4 tomasterFebruary 14, 2018 12:58
@nicolas-grekas
Copy link
Member

Thank you@MyDigitalLife.

@nicolas-grekasnicolas-grekas merged commitd845406 intosymfony:masterFeb 14, 2018
nicolas-grekas added a commit that referenced this pull requestFeb 14, 2018
…gitalLife)This PR was merged into the 4.1-dev branch.Discussion----------[Validator] support protocolless urls validation| Q             | A| ------------- | ---| Branch?       | 3.4| Bug fix?      | no| New feature?  | yes| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets |#24287| License       | MITAs specified in issue#24287 URL's starting with no protocol but with just `//` are valid URL's and should be accepted by the validator. This pull request fixes the regex used to validate URL's.Commits-------d845406 [Validator] support protocolless urls validation
@fabpotfabpot mentioned this pull requestMay 7, 2018
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@javiereguiluzjaviereguiluzjaviereguiluz approved these changes

@xabbuhxabbuhxabbuh approved these changes

+2 more reviewers

@ro0NLro0NLro0NL left review comments

@asmshaonasmshaonasmshaon left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

4.1

Development

Successfully merging this pull request may close these issues.

9 participants

@MyDigitalLife@nicolas-grekas@fabpot@Simperfit@javiereguiluz@ro0NL@asmshaon@xabbuh@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp