Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -1110,6 +1110,7 @@ PHP 8.6 UPGRADE NOTES
. Improved performance of intval('+0b...', 2) and intval('0b...', 2).
. Improved performance of str_split().
. Improved performance of str_pad().
. Improved performance of str_repeat() when the multiplier is 1.

- URI:
. Improved performance of Uri\WhatWg\Url::parse() when collecting
Expand Down
1 change: 0 additions & 1 deletion Zend/Optimizer/zend_func_infos.h
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,6 @@ static const func_info_t func_infos[] = {
F1("hebrev", MAY_BE_STRING),
F1("strip_tags", MAY_BE_STRING),
F1("str_getcsv", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_STRING|MAY_BE_ARRAY_OF_NULL),
F1("str_repeat", MAY_BE_STRING),
F1("count_chars", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_LONG|MAY_BE_STRING),
F1("localeconv", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_LONG|MAY_BE_ARRAY_OF_STRING|MAY_BE_ARRAY_OF_ARRAY),
F1("sscanf", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_ANY|MAY_BE_LONG|MAY_BE_NULL),
Expand Down
23 changes: 23 additions & 0 deletions ext/opcache/tests/jit/str_repeat_refcount.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--TEST--
str_repeat() may return a shared string
--EXTENSIONS--
opcache
--INI--
opcache.enable=1
opcache.enable_cli=1
opcache.file_update_protection=0
opcache.jit=1205
opcache.jit_buffer_size=32M
--FILE--
<?php
function test(int $length): void {
$input = str_repeat('a', $length);
str_repeat($input, 1);
$overwrite = str_repeat('b', $length);
var_dump($input, $overwrite);
}
test(16);
?>
--EXPECT--
string(16) "aaaaaaaaaaaaaaaa"
string(16) "bbbbbbbbbbbbbbbb"
1 change: 0 additions & 1 deletion ext/standard/basic_functions.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -2593,7 +2593,6 @@ function parse_str(string $string, &$result): void {}
*/
function str_getcsv(string $string, string $separator = ",", string $enclosure = "\"", string $escape = "\\"): array {}

/** @refcount 1 */
function str_repeat(string $string, int $times): string {}

/**
Expand Down
2 changes: 1 addition & 1 deletion ext/standard/basic_functions_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions ext/standard/basic_functions_decl.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions ext/standard/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -5638,6 +5638,10 @@ PHP_FUNCTION(str_repeat)
if (ZSTR_LEN(input_str) == 0 || mult == 0)
RETURN_EMPTY_STRING();

if (mult == 1) {
RETURN_STR_COPY(input_str);
}

/* Initialize the result string */
result = zend_string_safe_alloc(ZSTR_LEN(input_str), mult, 0, 0);
result_len = ZSTR_LEN(input_str) * mult;
Expand Down
6 changes: 3 additions & 3 deletions ext/uri/php_uri.c
Original file line number Diff line number Diff line change
Expand Up @@ -1404,12 +1404,12 @@ PHP_METHOD(Uri_WhatWg_UrlBuilder, setFragment)
PHP_METHOD(Uri_WhatWg_UrlBuilder, build)
{
zval *base_url_zv = NULL;
zval *errors = NULL;
zval *soft_errors = NULL;

ZEND_PARSE_PARAMETERS_START(0, 2)
Z_PARAM_OPTIONAL
Z_PARAM_OBJECT_OF_CLASS_OR_NULL(base_url_zv, php_uri_ce_whatwg_url)
Z_PARAM_ZVAL(errors)
Z_PARAM_ZVAL(soft_errors)
ZEND_PARSE_PARAMETERS_END();

const zval *scheme = Z_WHATWG_URL_PROP_SCHEME_DEREF_P(ZEND_THIS);
Expand All @@ -1430,7 +1430,7 @@ PHP_METHOD(Uri_WhatWg_UrlBuilder, build)

lxb_url_t *lexbor_url = php_uri_parser_whatwg_build_from_zval(
base_url, scheme, username, password, host, port, path, query, fragment,
errors
soft_errors
);
if (lexbor_url == NULL) {
RETURN_THROWS();
Expand Down
4 changes: 2 additions & 2 deletions ext/uri/php_uri.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,8 @@ public function setQuery(?string $query): static {}

public function setFragment(?string $fragment): static {}

/** @param array $errors */
public function build(?\Uri\WhatWg\Url $baseUrl = null, &$errors = null): \Uri\WhatWg\Url {}
/** @param array $softErrors */
public function build(?\Uri\WhatWg\Url $baseUrl = null, &$softErrors = null): \Uri\WhatWg\Url {}
}

/** @strict-properties */
Expand Down
4 changes: 2 additions & 2 deletions ext/uri/php_uri_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions ext/uri/php_uri_decl.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions ext/uri/tests/whatwg/builder/build_error_initialized_errors.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
--TEST--
Test Uri\WhatWg\UrlBuilder::setHost() - error - initializes validation errors
--FILE--
<?php

$builder = new Uri\WhatWg\UrlBuilder();

try {
$builder->setHost("example.com/path");
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
var_dump($e->errors);
}

?>
--EXPECTF--
Uri\WhatWg\InvalidUrlException: The specified host is malformed (HostInvalidCodePoint)
array(1) {
[0]=>
object(Uri\WhatWg\UrlValidationError)#%d (%d) {
["context"]=>
string(0) ""
["type"]=>
enum(Uri\WhatWg\UrlValidationErrorType::HostInvalidCodePoint)
["failure"]=>
bool(true)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--TEST--
Test Uri\WhatWg\UrlBuilder::build() - error - initializes errors for invalid component combinations
--FILE--
<?php

$builder = new Uri\WhatWg\UrlBuilder();
$builder->setScheme("foo");
$builder->setUsername("user");

try {
$builder->build();
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
var_dump($e->errors);
}

?>
--EXPECT--
Uri\WhatWg\InvalidUrlException: The specified URL cannot have username
array(0) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
--TEST--
Test Uri\WhatWg\UrlBuilder::build() - error - password with a host that normalizes to empty
--FILE--
<?php

$builder = new Uri\WhatWg\UrlBuilder();
$builder->setScheme("foo");
$builder->setHost("\t\n");
$builder->setPassword("pass");
$softErrors = ["unchanged"];

try {
$builder->build(softErrors: $softErrors);
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
var_dump($e->errors);
}

var_dump($softErrors);

?>
--EXPECTF--
Uri\WhatWg\InvalidUrlException: The specified URL cannot have password
array(1) {
[0]=>
object(Uri\WhatWg\UrlValidationError)#%d (%d) {
["context"]=>
string(2) "
"
["type"]=>
enum(Uri\WhatWg\UrlValidationErrorType::InvalidUrlUnit)
["failure"]=>
bool(false)
}
}
array(1) {
[0]=>
string(9) "unchanged"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
--TEST--
Test Uri\WhatWg\UrlBuilder::build() - error - port with a host that normalizes to empty
--FILE--
<?php

$builder = new Uri\WhatWg\UrlBuilder();
$builder->setScheme("foo");
$builder->setHost("\t\n");
$builder->setPort(123);
$softErrors = ["unchanged"];

try {
$builder->build(softErrors: $softErrors);
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
var_dump($e->errors);
}

var_dump($softErrors);

?>
--EXPECTF--
Uri\WhatWg\InvalidUrlException: The specified URL cannot have port
array(1) {
[0]=>
object(Uri\WhatWg\UrlValidationError)#%d (%d) {
["context"]=>
string(2) "
"
["type"]=>
enum(Uri\WhatWg\UrlValidationErrorType::InvalidUrlUnit)
["failure"]=>
bool(false)
}
}
array(1) {
[0]=>
string(9) "unchanged"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
--TEST--
Test Uri\WhatWg\UrlBuilder::build() - error - username with a host that normalizes to empty
--FILE--
<?php

$builder = new Uri\WhatWg\UrlBuilder();
$builder->setScheme("foo");
$builder->setHost("\t\n");
$builder->setUsername("user");
$softErrors = ["unchanged"];

try {
$builder->build(softErrors: $softErrors);
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
var_dump($e->errors);
}

var_dump($softErrors);

?>
--EXPECTF--
Uri\WhatWg\InvalidUrlException: The specified URL cannot have username
array(1) {
[0]=>
object(Uri\WhatWg\UrlValidationError)#%d (%d) {
["context"]=>
string(2) "
"
["type"]=>
enum(Uri\WhatWg\UrlValidationErrorType::InvalidUrlUnit)
["failure"]=>
bool(false)
}
}
array(1) {
[0]=>
string(9) "unchanged"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
--TEST--
Test Uri\WhatWg\UrlBuilder::build() - error - leaves soft errors unchanged
--FILE--
<?php

$builder = new Uri\WhatWg\UrlBuilder();
$builder->setScheme("ht\ttps");
$builder->setHost(null);
$softErrors = ["unchanged"];

try {
$builder->build(softErrors: $softErrors);
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
var_dump($e->errors);
}

var_dump($softErrors);

?>
--EXPECTF--
Uri\WhatWg\InvalidUrlException: The specified host is malformed (HostMissing)
array(2) {
[0]=>
object(Uri\WhatWg\UrlValidationError)#%d (%d) {
["context"]=>
string(4) " tps"
["type"]=>
enum(Uri\WhatWg\UrlValidationErrorType::InvalidUrlUnit)
["failure"]=>
bool(false)
}
[1]=>
object(Uri\WhatWg\UrlValidationError)#%d (%d) {
["context"]=>
string(0) ""
["type"]=>
enum(Uri\WhatWg\UrlValidationErrorType::HostMissing)
["failure"]=>
bool(true)
}
}
array(1) {
[0]=>
string(9) "unchanged"
}
Loading