From 499612482bc89f5f0067deafb0caf2655e6cb39a Mon Sep 17 00:00:00 2001 From: Sergey Bugaev Date: Tue, 14 Jan 2020 13:26:22 +0300 Subject: [PATCH] AK: Fix String[View]::split_view() returning an extra empty part If the last character was the separator and keep_empty is true, the previous if statement would have already appended the last empty part, so no need to do this again. This was even more problematic, because the result of split_view() is expected to consist of true substrings that are usable with the StringView::substring_view_starting_*_substring() methods, not of equal strings located elsewhere. Fixes https://github.com/SerenityOS/serenity/issues/970 See https://github.com/SerenityOS/serenity/pull/938 --- AK/String.cpp | 2 -- AK/StringView.cpp | 2 -- 2 files changed, 4 deletions(-) diff --git a/AK/String.cpp b/AK/String.cpp index b9f6beac933..c72d47a2650 100644 --- a/AK/String.cpp +++ b/AK/String.cpp @@ -153,8 +153,6 @@ Vector String::split_view(const char separator, bool keep_empty) con size_t taillen = length() - substart; if (taillen != 0 || keep_empty) v.append(substring_view(substart, taillen)); - if (characters()[length() - 1] == separator && keep_empty) - v.append(empty()); return v; } diff --git a/AK/StringView.cpp b/AK/StringView.cpp index ba34ebabc22..cd1fbd33447 100644 --- a/AK/StringView.cpp +++ b/AK/StringView.cpp @@ -35,8 +35,6 @@ Vector StringView::split_view(const char separator, bool keep_empty) size_t taillen = length() - substart; if (taillen != 0 || keep_empty) v.append(substring_view(substart, taillen)); - if (characters_without_null_termination()[length() - 1] == separator && keep_empty) - v.append(String::empty()); return v; }