From 5b8a5d7df4b487dcf6fca6855655f5329a54db8e Mon Sep 17 00:00:00 2001 From: Stanislav Malyshev Date: Fri, 10 Apr 2009 16:53:35 +0000 Subject: [PATCH] merge grapheme substr fix --- ext/intl/grapheme/grapheme_string.c | 2 +- ext/intl/tests/grapheme.phpt | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ext/intl/grapheme/grapheme_string.c b/ext/intl/grapheme/grapheme_string.c index 5abd33cc98..06388e312f 100755 --- a/ext/intl/grapheme/grapheme_string.c +++ b/ext/intl/grapheme/grapheme_string.c @@ -542,7 +542,7 @@ PHP_FUNCTION(grapheme_substr) length += iter_val; } - if ( UBRK_DONE == sub_str_end_pos ) { + if ( UBRK_DONE == sub_str_end_pos && length < 0) { intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "grapheme_substr: length not contained in string", 1 TSRMLS_CC ); diff --git a/ext/intl/tests/grapheme.phpt b/ext/intl/tests/grapheme.phpt index b5c0bdb833..c9982b16f4 100755 --- a/ext/intl/tests/grapheme.phpt +++ b/ext/intl/tests/grapheme.phpt @@ -334,7 +334,9 @@ function ut_main() array( "abc", 0, 2, "ab" ), array( "Abc", -4, 1, "false" ), array( "ababc", 1, 2, "ba" ), + array( "ababc", 0, 10, "ababc" ), + array( "a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", 0, 10 , "a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq" ), array( "a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", 5, "Opq" ), array( "a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", 5, -1, "Op" ), array( "a" . $char_a_ring_nfd . "bc" . $char_o_diaeresis_nfd . "Opq", 5, -2, "O" ), @@ -953,6 +955,8 @@ substring of "Abc" from "1" - grapheme_substr with length 1 = b == b substring of "abc" from "0" - grapheme_substr with length 2 = ab == ab substring of "Abc" from "-4" - grapheme_substr with length 1 = false == false substring of "ababc" from "1" - grapheme_substr with length 2 = ba == ba +substring of "ababc" from "0" - grapheme_substr with length 10 = ababc == ababc +substring of "aa%CC%8Abco%CC%88Opq" from "0" - grapheme_substr with length 10 = aa%CC%8Abco%CC%88Opq == aa%CC%8Abco%CC%88Opq substring of "aa%CC%8Abco%CC%88Opq" from "5" - grapheme_substr = Opq == Opq substring of "aa%CC%8Abco%CC%88Opq" from "5" - grapheme_substr with length -1 = Op == Op substring of "aa%CC%8Abco%CC%88Opq" from "5" - grapheme_substr with length -2 = O == O -- 2.40.0