Skip to content

Commit eba2805

Browse files
committed
Merge branch '2.4-develop' of github.com:MeCapron/magento2 into 2.4-develop-prs
2 parents a810741 + 5f473c3 commit eba2805

File tree

4 files changed

+82
-6
lines changed

4 files changed

+82
-6
lines changed

dev/tests/integration/testsuite/Magento/Framework/Url/Helper/DataTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ protected function setUp(): void
2121

2222
public function testGetCurrentBase64Url()
2323
{
24-
$this->assertEquals('aHR0cDovL2xvY2FsaG9zdDo4MS8,', $this->_helper->getCurrentBase64Url());
24+
$this->assertEquals('aHR0cDovL2xvY2FsaG9zdDo4MS8~', $this->_helper->getCurrentBase64Url());
2525
}
2626

2727
public function testGetEncodedUrl()
2828
{
29-
$this->assertEquals('aHR0cDovL2xvY2FsaG9zdDo4MS8,', $this->_helper->getEncodedUrl());
30-
$this->assertEquals('aHR0cDovL2V4YW1wbGUuY29tLw,,', $this->_helper->getEncodedUrl('http://example.com/'));
29+
$this->assertEquals('aHR0cDovL2xvY2FsaG9zdDo4MS8~', $this->_helper->getEncodedUrl());
30+
$this->assertEquals('aHR0cDovL2V4YW1wbGUuY29tLw~~', $this->_helper->getEncodedUrl('http://example.com/'));
3131
}
3232
}

dev/tests/integration/testsuite/Magento/Shipping/Helper/DataTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public function getTrackingPopupUrlBySalesModelDataProvider()
145145
'setId',
146146
42,
147147
'abc',
148-
'http://localhost/index.php/shipping/tracking/popup?hash=c2hpcF9pZDo0MjphYmM%2C'
148+
'http://localhost/index.php/shipping/tracking/popup?hash=c2hpcF9pZDo0MjphYmM%7E'
149149
],
150150
[\Magento\Sales\Model\Order\Shipment\Track::class,
151151
'setEntityId',

lib/internal/Magento/Framework/Url/Encoder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
class Encoder implements EncoderInterface
99
{
1010
/**
11-
* base64_encode() for URLs encoding
11+
* Method base64_encode() for URLs encoding
1212
*
1313
* @param string $url
1414
* @return string
1515
*/
1616
public function encode($url)
1717
{
18-
return strtr(base64_encode($url), '+/=', '-_,');
18+
return strtr(base64_encode($url), '+/=', '-_~');
1919
}
2020
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Framework\Url\Test\Unit;
9+
10+
use Magento\Framework\Url\Encoder;
11+
use PHPUnit\Framework\TestCase;
12+
13+
class EncoderTest extends TestCase
14+
{
15+
/**
16+
* @var Encoder|null
17+
*/
18+
private ?Encoder $encoder = null;
19+
20+
protected function setUp(): void
21+
{
22+
parent::setUp();
23+
24+
$this->encoder = new Encoder();
25+
}
26+
27+
public function testEncode(): void
28+
{
29+
$url = 'http://magento2.adobe/encoding';
30+
31+
self::assertEquals('aHR0cDovL21hZ2VudG8yLmFkb2JlL2VuY29kaW5n', $this->encoder->encode($url));
32+
}
33+
34+
/**
35+
* Equals should be replaced by a non-reserved character.
36+
*/
37+
public function testEncodeWithEndingSlash(): void
38+
{
39+
$url = 'http://magento2.adobe/encoding/with/longer/url/';
40+
41+
self::assertEquals(
42+
'aHR0cDovL21hZ2VudG8yLmFkb2JlL2VuY29kaW5nL3dpdGgvbG9uZ2VyL3VybC8~',
43+
$this->encoder->encode($url)
44+
);
45+
}
46+
47+
/**
48+
* @dataProvider rfc3986Urls
49+
*
50+
* @see https://www.rfc-editor.org/rfc/rfc3986.html#section-2.2
51+
*/
52+
public function testEncodeNotContainingRfc3986ReservedCharacters(string $url): void
53+
{
54+
$genDelims = [':', '/', '?', '#', '[', ']', '@'];
55+
$subDelims = ['!', '$', '&', '\'', '(', ')', '*', '+', ',', ';', '='];
56+
57+
$encodedUrl = $this->encoder->encode($url);
58+
59+
array_map(static function (string $value) use ($encodedUrl): void {
60+
self::assertStringNotContainsString($value, $encodedUrl);
61+
}, $genDelims);
62+
63+
array_map(static function (string $value) use ($encodedUrl): void {
64+
self::assertStringNotContainsString($value, $encodedUrl);
65+
}, $subDelims);
66+
}
67+
68+
public function rfc3986Urls(): array
69+
{
70+
return [
71+
['http://magento2.adobe/encoding/with/longer/url/'],
72+
['http://magento2.adobe/some/other/random/url?currency=eur&price=2'],
73+
['http://magento2.adobe/yet/not/done/url#anchor']
74+
];
75+
}
76+
}

0 commit comments

Comments
 (0)