diff options
-rw-r--r-- | AK/String.cpp | 3 | ||||
-rw-r--r-- | Tests/AK/TestString.cpp | 7 |
2 files changed, 10 insertions, 0 deletions
diff --git a/AK/String.cpp b/AK/String.cpp index ac443a0ce5..c92c3c54eb 100644 --- a/AK/String.cpp +++ b/AK/String.cpp @@ -181,6 +181,9 @@ String::String(String&& other) String& String::operator=(String&& other) { + if (!is_short_string()) + m_data->unref(); + m_data = exchange(other.m_data, nullptr); return *this; } diff --git a/Tests/AK/TestString.cpp b/Tests/AK/TestString.cpp index c453e6d74c..3cc88317a9 100644 --- a/Tests/AK/TestString.cpp +++ b/Tests/AK/TestString.cpp @@ -24,6 +24,13 @@ TEST_CASE(construct_empty) EXPECT_EQ(empty, ""sv); } +TEST_CASE(move_assignment) +{ + String string1 = MUST(String::from_utf8("hello"sv)); + string1 = MUST(String::from_utf8("friends!"sv)); + EXPECT_EQ(string1, "friends!"sv); +} + TEST_CASE(short_strings) { #ifdef AK_ARCH_64_BIT |