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
2 changes: 1 addition & 1 deletion benchmark/generate_diff.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function formatDiff(?int $baseInstructions, int $headInstructions): string {
}

function find_benchmarked_commit_hash(string $repo, string $commitHash): ?string {
$repeat = 10;
$repeat = 100;

while (true) {
if ($repeat-- <= 0) {
Expand Down
27 changes: 12 additions & 15 deletions ext/date/php_date.c
Original file line number Diff line number Diff line change
Expand Up @@ -3968,24 +3968,18 @@ PHP_FUNCTION(date_diff)
}
/* }}} */

static bool timezone_initialize(php_timezone_obj *tzobj, const char *tz, size_t tz_len, char **warning_message) /* {{{ */
static bool timezone_initialize(php_timezone_obj *tzobj, const zend_string *tz_zstr, char **warning_message) /* {{{ */
{
timelib_time *dummy_t = ecalloc(1, sizeof(timelib_time));
int dst, not_found;
const char *orig_tz = tz;
const char *tz = ZSTR_VAL(tz_zstr);

if (strlen(tz) != tz_len) {
if (warning_message) {
spprintf(warning_message, 0, "Timezone must not contain null bytes");
}
efree(dummy_t);
return false;
}
ZEND_ASSERT(!zend_str_has_nul_byte(tz_zstr) && "timezone should have been checked to not have null bytes");

dummy_t->z = timelib_parse_zone(&tz, &dst, dummy_t, &not_found, DATE_TIMEZONEDB, php_date_parse_tzfile_wrapper);
if ((dummy_t->z >= (100 * 60 * 60)) || (dummy_t->z <= (-100 * 60 * 60))) {
if (warning_message) {
spprintf(warning_message, 0, "Timezone offset is out of range (%s)", orig_tz);
spprintf(warning_message, 0, "Timezone offset is out of range (%s)", ZSTR_VAL(tz_zstr));
}
timelib_free(dummy_t->tz_abbr);
efree(dummy_t);
Expand All @@ -3994,15 +3988,15 @@ static bool timezone_initialize(php_timezone_obj *tzobj, const char *tz, size_t
dummy_t->dst = dst;
if (!not_found && (*tz != '\0')) {
if (warning_message) {
spprintf(warning_message, 0, "Unknown or bad timezone (%s)", orig_tz);
spprintf(warning_message, 0, "Unknown or bad timezone (%s)", ZSTR_VAL(tz_zstr));
}
timelib_free(dummy_t->tz_abbr);
efree(dummy_t);
return false;
}
if (not_found) {
if (warning_message) {
spprintf(warning_message, 0, "Unknown or bad timezone (%s)", orig_tz);
spprintf(warning_message, 0, "Unknown or bad timezone (%s)", ZSTR_VAL(tz_zstr));
}
efree(dummy_t);
return false;
Expand All @@ -4026,7 +4020,7 @@ PHP_FUNCTION(timezone_open)
ZEND_PARSE_PARAMETERS_END();

tzobj = Z_PHPTIMEZONE_P(php_date_instantiate(date_ce_timezone, return_value));
if (!timezone_initialize(tzobj, ZSTR_VAL(tz), ZSTR_LEN(tz), &warning_message)) {
if (!timezone_initialize(tzobj, tz, &warning_message)) {
php_error_docref(NULL, E_WARNING, "%s", warning_message);
efree(warning_message);
zval_ptr_dtor(return_value);
Expand All @@ -4047,7 +4041,7 @@ PHP_METHOD(DateTimeZone, __construct)
ZEND_PARSE_PARAMETERS_END();

tzobj = Z_PHPTIMEZONE_P(ZEND_THIS);
if (!timezone_initialize(tzobj, ZSTR_VAL(tz), ZSTR_LEN(tz), &exception_message)) {
if (!timezone_initialize(tzobj, tz, &exception_message)) {
zend_throw_exception_ex(date_ce_date_invalid_timezone_exception, 0, "DateTimeZone::__construct(): %s", exception_message);
efree(exception_message);
RETURN_THROWS();
Expand Down Expand Up @@ -4078,7 +4072,10 @@ static bool php_date_timezone_initialize_from_hash(zval **return_value, php_time
if (Z_TYPE_P(z_timezone) != IS_STRING) {
return false;
}
return timezone_initialize(*tzobj, Z_STRVAL_P(z_timezone), Z_STRLEN_P(z_timezone), NULL);
if (UNEXPECTED(zend_str_has_nul_byte(Z_STR_P(z_timezone)))) {
return false;
}
return timezone_initialize(*tzobj, Z_STR_P(z_timezone), NULL);
} /* }}} */

/* {{{ */
Expand Down
14 changes: 7 additions & 7 deletions ext/intl/tests/breakiter___construct.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ IntlBreakIterator::__construct() should not be callable
intl
--FILE--
<?php
ini_set("intl.error_level", E_WARNING);

new IntlBreakIterator();
try {
new IntlBreakIterator();
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}
?>
--EXPECTF--
Fatal error: Uncaught Error: Call to private IntlBreakIterator::__construct() from global scope in %s:%d
Stack trace:
#0 {main}
thrown in %s on line %d
--EXPECT--
Error: Call to private IntlBreakIterator::__construct() from global scope
47 changes: 19 additions & 28 deletions ext/intl/tests/breakiter___construct_error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,53 +5,44 @@ intl
--FILE--
<?php

function print_exception($e) {
echo "\nException: " . $e->getMessage() . " in " . $e->getFile() . " on line " . $e->getLine() . "\n";
}

//missing ; at the end:
try {
var_dump(new IntlRuleBasedBreakIterator('[\p{Letter}\uFFFD]+;[:number:]+'));
} catch (IntlException $e) {
print_exception($e);
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}
try {
var_dump(new IntlRuleBasedBreakIterator());
} catch (TypeError $e) {
print_exception($e);
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}
try {
var_dump(new IntlRuleBasedBreakIterator(1,2,3));
} catch (TypeError $e) {
print_exception($e);
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}
try {
var_dump(new IntlRuleBasedBreakIterator('[\p{Letter}\uFFFD]+;[:number:]+;', array()));
} catch (TypeError $e) {
print_exception($e);
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}
try {
var_dump(new IntlRuleBasedBreakIterator('[\p{Letter}\uFFFD]+;[:number:]+;', true));
} catch (IntlException $e) {
print_exception($e);
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}

$rbbi = new IntlRuleBasedBreakIterator(".;");
try {
$rbbi->__construct(".;");
} catch (Error $e) {
print_exception($e);
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}
?>
--EXPECTF--
Exception: IntlRuleBasedBreakIterator::__construct(): unable to create RuleBasedBreakIterator from rules (parse error on line 1, offset 31) in %s on line %d

Exception: IntlRuleBasedBreakIterator::__construct() expects at least 1 argument, 0 given in %s on line %d

Exception: IntlRuleBasedBreakIterator::__construct() expects at most 2 arguments, 3 given in %s on line %d

Exception: IntlRuleBasedBreakIterator::__construct(): Argument #2 ($compiled) must be of type bool, array given in %s on line %d

Exception: IntlRuleBasedBreakIterator::__construct(): unable to create instance from compiled rules in %s on line %d

Exception: IntlRuleBasedBreakIterator object is already constructed in %s on line %d
--EXPECT--
IntlException: IntlRuleBasedBreakIterator::__construct(): unable to create RuleBasedBreakIterator from rules (parse error on line 1, offset 31)
ArgumentCountError: IntlRuleBasedBreakIterator::__construct() expects at least 1 argument, 0 given
ArgumentCountError: IntlRuleBasedBreakIterator::__construct() expects at most 2 arguments, 3 given
TypeError: IntlRuleBasedBreakIterator::__construct(): Argument #2 ($compiled) must be of type bool, array given
IntlException: IntlRuleBasedBreakIterator::__construct(): unable to create instance from compiled rules
Error: IntlRuleBasedBreakIterator object is already constructed
1 change: 0 additions & 1 deletion ext/intl/tests/breakiter_clone_basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ IntlBreakIterator: clone handler
intl
--FILE--
<?php
ini_set("intl.error_level", E_WARNING);

$bi = new IntlRuleBasedBreakIterator('[\p{Letter}\uFFFD]+;[:number:]+;');
$bi_clone = clone $bi;
Expand Down
4 changes: 2 additions & 2 deletions ext/intl/tests/breakiter_createCodePointInstance_basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
IntlBreakIterator::createCodePointInstance(): basic test
--EXTENSIONS--
intl
--INI--
intl.default_locale=pt_PT
--FILE--
<?php
ini_set("intl.error_level", E_WARNING);
ini_set("intl.default_locale", "pt_PT");

$text = 'ตัวอย่างข้อความ';

Expand Down
2 changes: 0 additions & 2 deletions ext/intl/tests/breakiter_current_basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ IntlBreakIterator::current(): basic test
intl
--FILE--
<?php
ini_set("intl.error_level", E_WARNING);
ini_set("intl.default_locale", "pt_PT");

$bi = IntlBreakIterator::createWordInstance('pt');
var_dump($bi->current());
Expand Down
4 changes: 2 additions & 2 deletions ext/intl/tests/breakiter_factories_basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
IntlBreakIterator factories: basic tests
--EXTENSIONS--
intl
--INI--
intl.default_locale=ja
--FILE--
<?php
ini_set("intl.error_level", E_WARNING);
ini_set("intl.default_locale", "ja");

$m = array('createWordInstance', 'createLineInstance', 'createCharacterInstance',
'createSentenceInstance', 'createTitleInstance');
Expand Down
1 change: 0 additions & 1 deletion ext/intl/tests/breakiter_first_basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ IntlBreakIterator::first(): basic test
intl
--FILE--
<?php
ini_set("intl.error_level", E_WARNING);

$bi = IntlBreakIterator::createWordInstance('pt');
$bi->setText('foo bar trans');
Expand Down
2 changes: 0 additions & 2 deletions ext/intl/tests/breakiter_following_basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ IntlBreakIterator::following(): basic test
intl
--FILE--
<?php
ini_set("intl.error_level", E_WARNING);
ini_set("intl.default_locale", "pt_PT");

$bi = IntlBreakIterator::createWordInstance('pt');
$bi->setText('foo bar trans zoo bee');
Expand Down
2 changes: 0 additions & 2 deletions ext/intl/tests/breakiter_getLocale_basic2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ intl
<?php if (version_compare(INTL_ICU_VERSION, '64.0') >= 0) die('skip for ICU < 64.0'); ?>
--FILE--
<?php
ini_set("intl.error_level", E_WARNING);
ini_set("intl.default_locale", "pt_PT");

$bi = IntlBreakIterator::createSentenceInstance('pt');

Expand Down
2 changes: 0 additions & 2 deletions ext/intl/tests/breakiter_getLocale_basic3.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ intl
<?php if (version_compare(INTL_ICU_VERSION, '64.0') < 0) die('skip for ICU >= 64.0'); ?>
--FILE--
<?php
ini_set("intl.error_level", E_WARNING);
ini_set("intl.default_locale", "pt_PT");

$bi = IntlBreakIterator::createSentenceInstance('pt');

Expand Down
2 changes: 0 additions & 2 deletions ext/intl/tests/breakiter_getPartsIterator_basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ if (version_compare(INTL_ICU_VERSION, '57.1') > 0) die('skip for ICU <= 57.1');
?>
--FILE--
<?php
ini_set("intl.error_level", E_WARNING);
ini_set("intl.default_locale", "pt_PT");

$bi = IntlBreakIterator::createWordInstance('pt');
$pi = $bi->getPartsIterator();
Expand Down
2 changes: 0 additions & 2 deletions ext/intl/tests/breakiter_getPartsIterator_basic2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ if (version_compare(INTL_ICU_VERSION, '57.1') <= 0) die('skip for ICU > 57.1');
?>
--FILE--
<?php
ini_set("intl.error_level", E_WARNING);
ini_set("intl.default_locale", "pt_PT");

$bi = IntlBreakIterator::createWordInstance('pt');
$pi = $bi->getPartsIterator();
Expand Down
1 change: 0 additions & 1 deletion ext/intl/tests/breakiter_getPartsIterator_error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ IntlBreakIterator::getPartsIterator(): bad args
intl
--FILE--
<?php
ini_set("intl.default_locale", "pt_PT");

$it = IntlBreakIterator::createWordInstance(NULL);

Expand Down
4 changes: 2 additions & 2 deletions ext/intl/tests/breakiter_getPartsIterator_var1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
IntlBreakIterator::getPartsIterator(): argument variations
--EXTENSIONS--
intl
--INI--
intl.default_locale=pt_PT
--FILE--
<?php
ini_set("intl.error_level", E_WARNING);
ini_set("intl.default_locale", "pt_PT");

$text = 'foo bar tao';

Expand Down
1 change: 0 additions & 1 deletion ext/intl/tests/breakiter_getText_basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ IntlBreakIterator::getText(): basic test
intl
--FILE--
<?php
ini_set("intl.error_level", E_WARNING);

$bi = IntlBreakIterator::createWordInstance('pt');
var_dump($bi->getText());
Expand Down
2 changes: 0 additions & 2 deletions ext/intl/tests/breakiter_isBoundary_basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ IntlBreakIterator::isBoundary(): basic test
intl
--FILE--
<?php
ini_set("intl.error_level", E_WARNING);
ini_set("intl.default_locale", "pt_PT");

$bi = IntlBreakIterator::createWordInstance('pt');
$bi->setText('foo bar trans zoo bee');
Expand Down
1 change: 0 additions & 1 deletion ext/intl/tests/breakiter_last_basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ IntlBreakIterator::last(): basic test
intl
--FILE--
<?php
ini_set("intl.error_level", E_WARNING);

$bi = IntlBreakIterator::createWordInstance('pt');
$bi->setText('foo bar trans');
Expand Down
2 changes: 0 additions & 2 deletions ext/intl/tests/breakiter_next_basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ IntlBreakIterator::next(): basic test
intl
--FILE--
<?php
ini_set("intl.error_level", E_WARNING);
ini_set("intl.default_locale", "pt_PT");

$bi = IntlBreakIterator::createWordInstance('pt');
$bi->setText('foo bar trans zoo bee');
Expand Down
2 changes: 0 additions & 2 deletions ext/intl/tests/breakiter_preceding_basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ if (version_compare(INTL_ICU_VERSION, '57.1') > 0) die('skip for ICU <= 57.1');
?>
--FILE--
<?php
ini_set("intl.error_level", E_WARNING);
ini_set("intl.default_locale", "pt_PT");

$bi = IntlBreakIterator::createWordInstance('pt');
$bi->setText('foo bar trans zoo bee');
Expand Down
2 changes: 0 additions & 2 deletions ext/intl/tests/breakiter_preceding_basic2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ if (version_compare(INTL_ICU_VERSION, '57.1') <= 0) die('skip for ICU > 57.1');
?>
--FILE--
<?php
ini_set("intl.error_level", E_WARNING);
ini_set("intl.default_locale", "pt_PT");

$bi = IntlBreakIterator::createWordInstance('pt');
$bi->setText('foo bar trans zoo bee');
Expand Down
2 changes: 0 additions & 2 deletions ext/intl/tests/breakiter_previous_basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ IntlBreakIterator::previous(): basic test
intl
--FILE--
<?php
ini_set("intl.error_level", E_WARNING);
ini_set("intl.default_locale", "pt_PT");

$bi = IntlBreakIterator::createWordInstance('pt');
$bi->setText('foo bar trans');
Expand Down
1 change: 0 additions & 1 deletion ext/intl/tests/breakiter_setText_basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ IntlBreakIterator::setText(): basic test
intl
--FILE--
<?php
ini_set("intl.error_level", E_WARNING);

class A {
function __tostring() { return 'aaa'; }
Expand Down
6 changes: 2 additions & 4 deletions ext/intl/tests/bug58756_MessageFormatter_variant2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
Bug #58756: w.r.t MessageFormatter
--EXTENSIONS--
intl
--INI--
date.timezone=America/New_York
--SKIPIF--
<?php
if (str_contains(PHP_OS, 'FreeBSD')) {
Expand All @@ -10,13 +12,9 @@ if (str_contains(PHP_OS, 'FreeBSD')) {
?>
--FILE--
<?php
ini_set("intl.error_level", E_WARNING);
//ini_set("intl.default_locale", "nl");

$time = 1247013673;

ini_set('date.timezone', 'America/New_York');

$msgf = new MessageFormatter('en_US', '{0,date,full} {0,time,h:m:s a V}');

echo "date: " . date('l, F j, Y g:i:s A T', $time) . "\n";
Expand Down
Loading
Loading