-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix issue with special characters (#11)
Validation of each component is always done for a new url instance, otherwise not percent encoded special characters in path, query or fragment lead to an InvalidUrlException. Also prevent double encoding percent encoded characters in path, query or fragment.
- Loading branch information
Showing
3 changed files
with
141 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,10 +24,6 @@ public function testValidateUrl() | |
$validator->url(' https://wwww.example.com '), | ||
'https://wwww.example.com' | ||
); | ||
$this->assertEquals( | ||
$validator->url('ssh://username@host:/path/to/somewhere'), | ||
'ssh://username@host:/path/to/somewhere' | ||
); | ||
$this->assertEquals( | ||
$validator->url('ftp://username:[email protected]'), | ||
'ftp://username:[email protected]' | ||
|
@@ -215,12 +211,17 @@ public function testValidatePath() | |
$this->assertEquals($validator->path('/(foo)/*bar+'), '/(foo)/*bar+'); | ||
$this->assertEquals($validator->path('/foo,bar;baz:'), '/foo,bar;baz:'); | ||
$this->assertEquals($validator->path('/foo=bar@baz'), '/foo=bar@baz'); | ||
$this->assertEquals($validator->path('/foo%bar'), '/foo%25bar'); | ||
$this->assertEquals($validator->path('no/leading/slash'), 'no/leading/slash'); | ||
$this->assertEquals($validator->path('/"foo"'), '/%22foo%22'); | ||
$this->assertEquals($validator->path('/foo\\bar'), '/foo%5Cbar'); | ||
$this->assertEquals($validator->path('/bößer/pfad'), '/b%C3%B6%C3%9Fer/pfad'); | ||
$this->assertEquals($validator->path('/<html>'), '/%3Chtml%3E'); | ||
|
||
// Percent character not encoded (to %25) because %ba could be legitimate percent encoded character. | ||
$this->assertEquals($validator->path('/foo%bar'), '/foo%bar'); | ||
|
||
// Percent character encoded because %ga isn't a valid percent encoded character. | ||
$this->assertEquals($validator->path('/foo%gar'), '/foo%25gar'); | ||
} | ||
|
||
public function testValidateQuery() | ||
|
@@ -240,6 +241,7 @@ public function testValidateQuery() | |
$this->assertEquals($validator->query('föo=bar'), 'f%C3%B6o=bar'); | ||
$this->assertEquals($validator->query('boeßer=query'), 'boe%C3%9Fer=query'); | ||
$this->assertEquals($validator->query('foo`=bar'), 'foo%60=bar'); | ||
$this->assertEquals($validator->query('foo%25bar=baz'), 'foo%25bar=baz'); | ||
} | ||
|
||
public function testValidateFragment() | ||
|
@@ -260,5 +262,6 @@ public function testValidateFragment() | |
$this->assertEquals($validator->fragment('frägment'), 'fr%C3%A4gment'); | ||
$this->assertEquals($validator->fragment('boeßesfragment'), 'boe%C3%9Fesfragment'); | ||
$this->assertEquals($validator->fragment('fragment`'), 'fragment%60'); | ||
$this->assertEquals($validator->fragment('fragm%E2%82%ACnt'), 'fragm%E2%82%ACnt'); | ||
} | ||
} |