Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:Ledest:erlang:24
erlang
1088-Fix-behavior-of-re-split-3-with-trim-optio...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 1088-Fix-behavior-of-re-split-3-with-trim-option-for-empt.patch of Package erlang
From 1cae114ab31b99c74cda052c61d6b12fa668c17e Mon Sep 17 00:00:00 2001 From: Maria Scott <maria-12648430@hnc-agency.org> Date: Mon, 30 Sep 2024 13:35:26 +0200 Subject: [PATCH] Fix behavior of re:split/3 with trim option for empty subjects re:split/3 with the trim option set would return a list with an empty binary if the pattern was not empty. This was inconsistent with both Perl split and binary:split/3. --- lib/stdlib/src/re.erl | 2 ++ lib/stdlib/test/re_SUITE.erl | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/lib/stdlib/src/re.erl b/lib/stdlib/src/re.erl index 8351619b49..31103b3931 100644 --- a/lib/stdlib/src/re.erl +++ b/lib/stdlib/src/re.erl @@ -1081,6 +1081,8 @@ split(Subject,RE,Options) -> case compile_split(RE,NewOpt) of {error,_Err} -> throw(badre); + {_PreCompiled, _NumSub, _RunOpt} when FlatSubject =:= <<>> -> + []; {PreCompiled, NumSub, RunOpt} -> %% OK, lets run case re:run(FlatSubject,PreCompiled,RunOpt ++ [global]) of diff --git a/lib/stdlib/test/re_SUITE.erl b/lib/stdlib/test/re_SUITE.erl index 9a7b5b470e..39d76a5993 100644 --- a/lib/stdlib/test/re_SUITE.erl +++ b/lib/stdlib/test/re_SUITE.erl @@ -476,6 +476,10 @@ split_autogen(Config) when is_list(Config) -> %% Test special options to split. split_options(Config) when is_list(Config) -> + ok = splittest("", "", [trim], []), + ok = splittest("", " ", [trim], []), + ok = splittest("", "()", [group, trim], []), + ok = splittest("", "( )", [group, trim], []), ok = splittest("a b c ","( )",[group,trim],[[<<"a">>,<<" ">>],[<<"b">>,<<" ">>],[<<"c">>,<<" ">>]]), ok = splittest("a b c ","( )",[group,{parts,0}],[[<<"a">>,<<" ">>],[<<"b">>,<<" ">>],[<<"c">>,<<" ">>]]), ok = splittest("a b c ","( )",[{parts,infinity},group],[[<<"a">>,<<" ">>],[<<"b">>,<<" ">>],[<<"c">>,<<" ">>],[<<>>]]), -- 2.43.0
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor