Skip to content

Commit b31a5b2

Browse files
committed
Fix str_decrement() on "1"
Closes GH-12339
1 parent 769f41b commit b31a5b2

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

NEWS

+3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ PHP NEWS
2525
- SimpleXML:
2626
. Apply iterator fixes only on master. (nielsdos)
2727

28+
- Standard:
29+
. Fixed str_decrement() on "1". (ilutov)
30+
2831
- XSL:
2932
. Fix type error on XSLTProcessor::transformToDoc return value with
3033
SimpleXML. (nielsdos)

ext/standard/string.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1289,7 +1289,7 @@ PHP_FUNCTION(str_decrement)
12891289
}
12901290
} while (carry && position-- > 0);
12911291

1292-
if (UNEXPECTED(carry || ZSTR_VAL(decremented)[0] == '0')) {
1292+
if (UNEXPECTED(carry || (ZSTR_VAL(decremented)[0] == '0' && ZSTR_LEN(decremented) > 1))) {
12931293
if (ZSTR_LEN(decremented) == 1) {
12941294
zend_string_release_ex(decremented, /* persistent */ false);
12951295
zend_argument_value_error(1, "\"%s\" is out of decrement range", ZSTR_VAL(str));

ext/standard/tests/strings/str_decrement_basic.phpt

+3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ $strictlyAlphaNumeric = [
2828
"d",
2929
"D",
3030
"4",
31+
"1",
3132
];
3233

3334
foreach ($strictlyAlphaNumeric as $s) {
@@ -77,3 +78,5 @@ string(1) "C"
7778
string(1) "D"
7879
string(1) "3"
7980
string(1) "4"
81+
string(1) "0"
82+
string(1) "1"

0 commit comments

Comments
 (0)