Browse Source
uri: Throw when trying to modify URI objects after creation (#19768)
uri: Throw when trying to modify URI objects after creation (#19768)
This will also fix a memory leak, since the constructor did not free any pre-existing `->uri`.pull/19080/merge
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 127 additions and 1 deletions
@ -0,0 +1,117 @@ |
|||
--TEST-- |
|||
Test that overwriting the URI is not possible |
|||
--EXTENSIONS-- |
|||
uri |
|||
--FILE-- |
|||
<?php |
|||
|
|||
$uri = new Uri\WhatWg\Url('https://example.com'); |
|||
try { |
|||
$uri->__construct('ftp://example.org'); |
|||
} catch (Throwable $e) { |
|||
echo $e::class, ": ", $e->getMessage(), PHP_EOL; |
|||
} |
|||
var_dump($uri); |
|||
|
|||
$uri = new Uri\WhatWg\Url('https://example.com'); |
|||
try { |
|||
$uri->__unserialize([['uri' => 'ftp://example.org'], []]); |
|||
} catch (Throwable $e) { |
|||
echo $e::class, ": ", $e->getMessage(), PHP_EOL; |
|||
} |
|||
var_dump($uri); |
|||
|
|||
$uri = new Uri\Rfc3986\Uri('https://example.com'); |
|||
try { |
|||
$uri->__construct('ftp://example.org'); |
|||
} catch (Throwable $e) { |
|||
echo $e::class, ": ", $e->getMessage(), PHP_EOL; |
|||
} |
|||
var_dump($uri); |
|||
|
|||
$uri = new Uri\Rfc3986\Uri('https://example.com'); |
|||
try { |
|||
$uri->__unserialize([['uri' => 'ftp://example.org'], []]); |
|||
} catch (Throwable $e) { |
|||
echo $e::class, ": ", $e->getMessage(), PHP_EOL; |
|||
} |
|||
var_dump($uri); |
|||
|
|||
?> |
|||
--EXPECTF-- |
|||
Error: Cannot modify readonly object of class Uri\WhatWg\Url |
|||
object(Uri\WhatWg\Url)#%d (8) { |
|||
["scheme"]=> |
|||
string(5) "https" |
|||
["username"]=> |
|||
NULL |
|||
["password"]=> |
|||
NULL |
|||
["host"]=> |
|||
string(11) "example.com" |
|||
["port"]=> |
|||
NULL |
|||
["path"]=> |
|||
string(1) "/" |
|||
["query"]=> |
|||
NULL |
|||
["fragment"]=> |
|||
NULL |
|||
} |
|||
Exception: Invalid serialization data for Uri\WhatWg\Url object |
|||
object(Uri\WhatWg\Url)#%d (8) { |
|||
["scheme"]=> |
|||
string(5) "https" |
|||
["username"]=> |
|||
NULL |
|||
["password"]=> |
|||
NULL |
|||
["host"]=> |
|||
string(11) "example.com" |
|||
["port"]=> |
|||
NULL |
|||
["path"]=> |
|||
string(1) "/" |
|||
["query"]=> |
|||
NULL |
|||
["fragment"]=> |
|||
NULL |
|||
} |
|||
Error: Cannot modify readonly object of class Uri\Rfc3986\Uri |
|||
object(Uri\Rfc3986\Uri)#%d (8) { |
|||
["scheme"]=> |
|||
string(5) "https" |
|||
["username"]=> |
|||
NULL |
|||
["password"]=> |
|||
NULL |
|||
["host"]=> |
|||
string(11) "example.com" |
|||
["port"]=> |
|||
NULL |
|||
["path"]=> |
|||
string(0) "" |
|||
["query"]=> |
|||
NULL |
|||
["fragment"]=> |
|||
NULL |
|||
} |
|||
Exception: Invalid serialization data for Uri\Rfc3986\Uri object |
|||
object(Uri\Rfc3986\Uri)#%d (8) { |
|||
["scheme"]=> |
|||
string(5) "https" |
|||
["username"]=> |
|||
NULL |
|||
["password"]=> |
|||
NULL |
|||
["host"]=> |
|||
string(11) "example.com" |
|||
["port"]=> |
|||
NULL |
|||
["path"]=> |
|||
string(0) "" |
|||
["query"]=> |
|||
NULL |
|||
["fragment"]=> |
|||
NULL |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue