Skip to content

Commit

Permalink
fix url encoding of slashes
Browse files Browse the repository at this point in the history
  • Loading branch information
nadar committed Oct 21, 2020
1 parent 18835c2 commit 95001c8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,6 @@ public function merge(Url $url)
*/
private function processEncoding($value)
{
return $this->encode ? urlencode($value) : $value;
return $this->encode ? implode("/", array_map("urlencode", explode("/", $value))) : $value;
}
}
13 changes: 10 additions & 3 deletions tests/UrlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,24 @@ public function testEncode()
// https://www.ahv-iv.ch/de/Merkblätter-Formulare/Formulare/Elektronische-Formulare/AHV-Formulare/318260-Anmeldung-für-einen-Versicherungsausweis
// https://www.ahv-iv.ch/it/Opuscoli-Moduli/Moduli/Prestazioni-dellIPG-servizio-e-maternità

$u = new Url('https://www.ahv-iv.ch/de/Merkblätter-Formulare/Formulare/Elektronische-Formulare/AHV-Formulare/318260-Anmeldung-für-einen-Versicherungsausweis');
$u = new Url('https://www.ahv-iv.ch/de/Merkblätter/Versicherungsausweis');
$u->encode = true;

$this->assertSame('%2Fde%2FMerkbl%C3%A4tter-Formulare%2FFormulare%2FElektronische-Formulare%2FAHV-Formulare%2F318260-Anmeldung-f%C3%BCr-einen-Versicherungsausweis', $u->getPath());
$this->assertSame('/de/Merkbl%C3%A4tter/Versicherungsausweis', $u->getPath());

$u = new Url('https://luya.io/äà');
$this->assertSame('https://luya.io/äà', $u->getNormalized());

$u = new Url('https://luya.io/äà');
$this->assertSame('https://luya.io/äà', $u->getNormalized());
$u->encode = true;
$this->assertSame('https://luya.io/%C3%A4%C3%A0', $u->getNormalized());
$this->assertSame('/%C3%A4%C3%A0', $u->getPath());
$this->assertSame('https://luya.io/äà', urldecode($u->getNormalized()));

$u = new Url('https://luya.io/a/a');
$u->encode = true;
$this->assertSame('https://luya.io/%2F%C3%A4%C3%A0', $u->getNormalized());
$this->assertSame('https://luya.io/a/a', $u->getNormalized());
}

public function testInvalidUrl()
Expand Down

0 comments on commit 95001c8

Please sign in to comment.