Skip to content

Commit 3a16aea

Browse files
authored
[6.x] Change urlencode and rawurlencode modifiers to not ignore forward slashes (#11812)
1 parent 0c01bd4 commit 3a16aea

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

src/Modifiers/CoreModifiers.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1934,6 +1934,16 @@ public function random($value)
19341934
* @return string
19351935
*/
19361936
public function rawurlencode($value)
1937+
{
1938+
return rawurlencode($value);
1939+
}
1940+
1941+
/**
1942+
* URL-encode according to RFC 3986, but allowing slashes to persist
1943+
*
1944+
* @return string
1945+
*/
1946+
public function rawurlencode_except_slashes($value)
19371947
{
19381948
return implode('/', array_map('rawurlencode', explode('/', $value)));
19391949
}
@@ -2844,6 +2854,16 @@ public function urldecode($value)
28442854
* @return string
28452855
*/
28462856
public function urlencode($value)
2857+
{
2858+
return urlencode($value);
2859+
}
2860+
2861+
/**
2862+
* URL-encodes string, but allowing slashes to persist
2863+
*
2864+
* @return string
2865+
*/
2866+
public function urlencode_except_slashes($value)
28472867
{
28482868
return implode('/', array_map('urlencode', explode('/', $value)));
28492869
}

tests/Antlers/Runtime/CoreModifiersTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ protected function setUp(): void
8080
],
8181
'remove_left_var' => 'https://',
8282
'test_currency_symbol' => '£32.00',
83+
'test_url_encode' => 'please and thank you/Mommy',
8384
];
8485
}
8586

@@ -565,6 +566,26 @@ public function test_null_values_on_count_does_not_trigger_error()
565566
$this->assertSame('No', $this->renderString($template, ['variable' => collect()], true));
566567
$this->assertSame('Yes', $this->renderString($template, ['variable' => ['One']], true));
567568
}
569+
570+
public function test_urlencode()
571+
{
572+
$this->assertSame('please+and+thank+you%2FMommy', $this->resultOf('{{ test_url_encode | urlencode }}'));
573+
}
574+
575+
public function test_urlencode_except_slashes()
576+
{
577+
$this->assertSame('please+and+thank+you/Mommy', $this->resultOf('{{ test_url_encode | urlencode_except_slashes }}'));
578+
}
579+
580+
public function test_rawurlencode()
581+
{
582+
$this->assertSame('please%20and%20thank%20you%2FMommy', $this->resultOf('{{ test_url_encode | rawurlencode }}'));
583+
}
584+
585+
public function test_rawurlencode_except_slashes()
586+
{
587+
$this->assertSame('please%20and%20thank%20you/Mommy', $this->resultOf('{{ test_url_encode | rawurlencode_except_slashes }}'));
588+
}
568589
}
569590

570591
class SimpleEntryObject implements Arrayable

0 commit comments

Comments
 (0)