]> granicus.if.org Git - php/commit
Normalize substr() behavior
authorNikita Popov <nikita.ppv@gmail.com>
Tue, 22 Sep 2020 07:56:08 +0000 (09:56 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Fri, 25 Sep 2020 07:58:21 +0000 (09:58 +0200)
commit13b791c79c3b1aa69e51b640c84829b98cd50b03
tree3fd1a3a5472b07c24e3a8af91e4138bd1c9b6f7c
parent17a789e27c31ca13ba4bab6fcfc265d2dd0589a2
Normalize substr() behavior

Make the behavior of substr(), mb_substr(), iconv_substr() and
grapheme_substr() consistent when it comes to the handling of
out of bounds offsets. substr() will now always clamp out of
bounds offsets to the string boundary. Cases that previously
returned false will now return an empty string. This means that
substr() itself *always* returns a string now (like mb_substr()
already did before.)

Closes GH-6182.
14 files changed:
ext/iconv/iconv.c
ext/iconv/tests/iconv_substr.phpt
ext/iconv/tests/iconv_substr_out_of_bounds.phpt [new file with mode: 0644]
ext/intl/grapheme/grapheme_string.c
ext/intl/grapheme/grapheme_util.c
ext/intl/tests/bug62759.phpt
ext/intl/tests/grapheme.phpt
ext/intl/tests/grapheme2.phpt
ext/intl/tests/grapheme_out_of_bounds.phpt
ext/standard/basic_functions.stub.php
ext/standard/basic_functions_arginfo.h
ext/standard/string.c
ext/standard/tests/strings/bug40754.phpt
ext/standard/tests/strings/substr.phpt