From cba5766bc876f72dcf8410a9852e14f187853b88 Mon Sep 17 00:00:00 2001 From: Seth Hall Date: Tue, 19 Apr 2011 22:24:46 -0400 Subject: [PATCH] Fixed the do_split bug and added a test. * do_split was having a problem if there was another match after the end of the number of separators. It would only return the match up to the point of the next match instead of the rest of the string. --- src/strings.bif | 4 +++- testing/btest/Baseline/bifs.string_splitting/out | 4 ++++ testing/btest/bifs/string_splitting.bro | 9 +++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 testing/btest/Baseline/bifs.string_splitting/out create mode 100644 testing/btest/bifs/string_splitting.bro diff --git a/src/strings.bif b/src/strings.bif index e41ae196b2..b31dac84ed 100644 --- a/src/strings.bif +++ b/src/strings.bif @@ -225,6 +225,8 @@ Val* do_split(StringVal* str_val, RE_Matcher* re, TableVal* other_sep, } Val* ind = new Val(++num, TYPE_COUNT); + if ( num_sep >= max_num_sep ) + offset = end_of_s-s; a->Assign(ind, new StringVal(offset, (const char*) s)); Unref(ind); @@ -238,7 +240,7 @@ Val* do_split(StringVal* str_val, RE_Matcher* re, TableVal* other_sep, a->Assign(ind, new StringVal(end_of_match, (const char*) s+offset)); Unref(ind); } - + if ( max_num_sep && num_sep >= max_num_sep ) break; diff --git a/testing/btest/Baseline/bifs.string_splitting/out b/testing/btest/Baseline/bifs.string_splitting/out new file mode 100644 index 0000000000..8157e6ecb9 --- /dev/null +++ b/testing/btest/Baseline/bifs.string_splitting/out @@ -0,0 +1,4 @@ +{ +[2] = Testing Test (http://www.example.com), +[1] = X-Mailer +} diff --git a/testing/btest/bifs/string_splitting.bro b/testing/btest/bifs/string_splitting.bro new file mode 100644 index 0000000000..1920db75a2 --- /dev/null +++ b/testing/btest/bifs/string_splitting.bro @@ -0,0 +1,9 @@ +# +# @TEST-EXEC: bro %INPUT >out +# @TEST-EXEC: btest-diff out + +event bro_init() + { + local a = "X-Mailer: Testing Test (http://www.example.com)"; + print split1(a, /:[[:blank:]]*/); + }