diff options
author | Idan Horowitz <idan.horowitz@gmail.com> | 2021-09-11 02:15:44 +0300 |
---|---|---|
committer | Idan Horowitz <idan.horowitz@gmail.com> | 2021-09-11 20:36:43 +0300 |
commit | 6704961c8250b44dc622e95821fd7e2b6bed673a (patch) | |
tree | bd540128659a2556acc51464552091fc3eb2e449 /Tests/AK | |
parent | aba4c9579ff8d36f739eb221e330782e5c3a5d9d (diff) | |
download | serenity-6704961c8250b44dc622e95821fd7e2b6bed673a.zip |
AK: Replace the mutable String::replace API with an immutable version
This removes the awkward String::replace API which was the only String
API which mutated the String and replaces it with a new immutable
version that returns a new String with the replacements applied. This
also fixes a couple of UAFs that were caused by the use of this API.
As an optimization an equivalent StringView::replace API was also added
to remove an unnecessary String allocations in the format of:
`String { view }.replace(...);`
Diffstat (limited to 'Tests/AK')
-rw-r--r-- | Tests/AK/TestString.cpp | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/Tests/AK/TestString.cpp b/Tests/AK/TestString.cpp index d5e7c970bb..fc55df1a5a 100644 --- a/Tests/AK/TestString.cpp +++ b/Tests/AK/TestString.cpp @@ -146,25 +146,21 @@ TEST_CASE(flystring) TEST_CASE(replace) { String test_string = "Well, hello Friends!"; - u32 replacements = test_string.replace("Friends", "Testers"); - EXPECT(replacements == 1); + + test_string = test_string.replace("Friends", "Testers"); EXPECT(test_string == "Well, hello Testers!"); - replacements = test_string.replace("ell", "e're", true); - EXPECT(replacements == 2); + test_string = test_string.replace("ell", "e're", true); EXPECT(test_string == "We're, he'reo Testers!"); - replacements = test_string.replace("!", " :^)"); - EXPECT(replacements == 1); + test_string = test_string.replace("!", " :^)"); EXPECT(test_string == "We're, he'reo Testers :^)"); test_string = String("111._.111._.111"); - replacements = test_string.replace("111", "|||", true); - EXPECT(replacements == 3); + test_string = test_string.replace("111", "|||", true); EXPECT(test_string == "|||._.|||._.|||"); - replacements = test_string.replace("|||", "111"); - EXPECT(replacements == 1); + test_string = test_string.replace("|||", "111"); EXPECT(test_string == "111._.|||._.|||"); } |