From 9e1497c758d4615482e76c05258f1b4812ef8f9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1t=C3=A9=20Kocsis?= Date: Fri, 18 Sep 2020 22:05:41 +0200 Subject: [PATCH] Fix consistency between grapheme_substr() and substr() --- ext/intl/grapheme/grapheme_string.c | 4 +++- ext/intl/tests/grapheme_substr.phpt | 31 +++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 ext/intl/tests/grapheme_substr.phpt diff --git a/ext/intl/grapheme/grapheme_string.c b/ext/intl/grapheme/grapheme_string.c index 8706381e58825..3d706c851aea1 100644 --- a/ext/intl/grapheme/grapheme_string.c +++ b/ext/intl/grapheme/grapheme_string.c @@ -375,7 +375,9 @@ PHP_FUNCTION(grapheme_substr) RETURN_THROWS(); } - if ( OUTSIDE_STRING(lstart, str_len)) { + if (str_len == 0 && lstart == 0) { + RETURN_EMPTY_STRING(); + } else if (OUTSIDE_STRING(lstart, str_len)) { zend_argument_value_error(2, "must be contained in argument #1 ($string)"); RETURN_THROWS(); } diff --git a/ext/intl/tests/grapheme_substr.phpt b/ext/intl/tests/grapheme_substr.phpt new file mode 100644 index 0000000000000..f56c18a8b2f26 --- /dev/null +++ b/ext/intl/tests/grapheme_substr.phpt @@ -0,0 +1,31 @@ +--TEST-- +Test grapheme_substr() function +--SKIPIF-- + +--FILE-- +getMessage() . "\n"; +} + +var_dump(grapheme_substr("abc", 0, 5)); + +try { + grapheme_substr("abc", 3, 5); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} + +?> +--EXPECT-- +string(0) "" +grapheme_substr(): Argument #2 ($start) must be contained in argument #1 ($string) +string(3) "abc" +grapheme_substr(): Argument #2 ($start) must be contained in argument #1 ($string)