-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Validator] su 8000 pport 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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,6 +65,30 @@ public function testValidUrls($url) | |
$this->assertNoViolation(); | ||
} | ||
|
||
/** | ||
* @dataProvider getValidRelativeUrls | ||
* @dataProvider getValidUrls | ||
*/ | ||
public function testValidRelativeUrl($url) | ||
{ | ||
$constraint = new Url(array( | ||
'relativeProtocol' => true, | ||
)); | ||
|
||
$this->validator->validate($url, $constraint); | ||
|
||
$this->assertNoViolation(); | ||
} | ||
|
||
public function getValidRelativeUrls() | ||
{ | ||
return array( | ||
array('//google.com'), | ||
array('//symfony.fake/blog/'), | ||
array('//symfony.com/search?type=&q=url+validator'), | ||
); | ||
} | ||
|
||
public function getValidUrls() | ||
{ | ||
return array( | ||
|
@@ -147,6 +171,46 @@ public function testInvalidUrls($url) | |
->assertRaised(); | ||
} | ||
|
||
/** | ||
* @dataProvider getInvalidRelativeUrls | ||
* @dataProvider getInvalidUrls | ||
*/ | ||
public function testInvalidRelativeUrl($url) | ||
{ | ||
$constraint = new Url(array( | ||
'message' => 'myMessage', | ||
'relativeProtocol' => true, | ||
)); | ||
|
||
$this->validator->validate($url, $constraint); | ||
|
||
$this->buildViolation('myMessage') | ||
->setParameter('{{ value }}', '"'.$url.'"') | ||
->setCode(Url::INVALID_URL_ERROR) | ||
->assertRaised(); | ||
} | ||
|
||
public function getInvalidRelativeUrls() | ||
{ | ||
return array( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason why we are not using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's because Symfony coding standards. We can't easily change the existing code from There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 the |
||
array('/google.com'), | ||
array('//goog_le.com'), | ||
array('//google.com::aa'), | ||
array('//google.com:aa'), | ||
array('//127.0.0.1:aa/'), | ||
array('//[::1'), | ||
array('//hello.☎/'), | ||
array('//:password@symfony.com'), | ||
array('//:password@@symfony.com'), | ||
array('//username:passwordsymfony.com'), | ||
array('//usern@me:password@symfony.com'), | ||
array('//example.com/exploit.html?<script>alert(1);</script>'), | ||
array('//example.com/exploit.html?hel lo'), | ||
array('//example.com/exploit.html?not_a%hex'), | ||
array('//'), | ||
); | ||
} | ||
|
||
public function getInvalidUrls() | ||
{ | ||
return array( | ||
|
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test has both
getValidRelativeUrls
andgetValidUrls
as a data provider. That covers both absolute and relative URL's. Or am I missing something?There was a problem hiding this comment.
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.