1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Fix str_decrement() on "1"

Closes GH-12339
This commit is contained in:
Ilija Tovilo
2023-10-01 18:12:11 +02:00
parent 769f41bb21
commit b31a5b2731
3 changed files with 7 additions and 1 deletions

3
NEWS
View File

@@ -25,6 +25,9 @@ PHP NEWS
- SimpleXML:
. Apply iterator fixes only on master. (nielsdos)
- Standard:
. Fixed str_decrement() on "1". (ilutov)
- XSL:
. Fix type error on XSLTProcessor::transformToDoc return value with
SimpleXML. (nielsdos)

View File

@@ -1289,7 +1289,7 @@ PHP_FUNCTION(str_decrement)
}
} while (carry && position-- > 0);
if (UNEXPECTED(carry || ZSTR_VAL(decremented)[0] == '0')) {
if (UNEXPECTED(carry || (ZSTR_VAL(decremented)[0] == '0' && ZSTR_LEN(decremented) > 1))) {
if (ZSTR_LEN(decremented) == 1) {
zend_string_release_ex(decremented, /* persistent */ false);
zend_argument_value_error(1, "\"%s\" is out of decrement range", ZSTR_VAL(str));

View File

@@ -28,6 +28,7 @@ $strictlyAlphaNumeric = [
"d",
"D",
"4",
"1",
];
foreach ($strictlyAlphaNumeric as $s) {
@@ -77,3 +78,5 @@ string(1) "C"
string(1) "D"
string(1) "3"
string(1) "4"
string(1) "0"
string(1) "1"