File tree Expand file tree Collapse file tree 2 files changed +19
-4
lines changed
lib/internal/Magento/Framework/Url Expand file tree Collapse file tree 2 files changed +19
-4
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,9 @@ class ValidatorTest extends TestCase
2323 /** @var string[] */
2424 protected $ expectedValidationMessages = [Uri::INVALID => "Invalid URL '%value%'. " ];
2525
26+ /** @var string[] */
27+ protected $ invalidURL = [Uri::INVALID => "Invalid URL 'php://filter'. " ];
28+
2629 protected function setUp (): void
2730 {
2831 $ objectManager = new ObjectManager ($ this );
@@ -59,4 +62,13 @@ public function testIsValidWhenInvalid()
5962 $ this ->assertFalse ($ this ->object ->isValid ('%value% ' ));
6063 $ this ->assertEquals ($ this ->expectedValidationMessages , $ this ->object ->getMessages ());
6164 }
65+
66+ public function testIsValidWhenInvalidURL ()
67+ {
68+ $ this ->laminasValidator
69+ ->method ('isValid ' )
70+ ->with ('php://filter ' );
71+ $ this ->assertFalse ($ this ->object ->isValid ('php://filter ' ));
72+ $ this ->assertEquals ($ this ->invalidURL , $ this ->object ->getMessages ());
73+ }
6274}
Original file line number Diff line number Diff line change @@ -55,11 +55,14 @@ public function isValid($value)
5555 $ this ->setValue ($ value );
5656
5757 $ valid = $ this ->validator ->isValid ($ value );
58-
59- if (!$ valid ) {
60- $ this ->error (Uri::INVALID );
58+ // phpcs:ignore Magento2.Functions.DiscouragedFunction
59+ $ protocol = parse_url ($ value ? $ value : '' , PHP_URL_SCHEME );
60+ if ($ valid && ($ protocol === 'https ' || $ protocol === 'http ' )) {
61+ return true ;
6162 }
6263
63- return $ valid ;
64+ $ this ->error (Uri::INVALID );
65+
66+ return false ;
6467 }
6568}
You can’t perform that action at this time.
0 commit comments