AK+Tests: Make null strings compare less than non-null strings

This behavior regressed in ca58c71faa.

Fixes #12213
This commit is contained in:
Daniel Bertalan 2022-01-30 16:53:49 +01:00 committed by Linus Groh
parent 3bb580ba1d
commit 8473f6caee
2 changed files with 8 additions and 5 deletions

View file

@ -206,8 +206,14 @@ public:
[[nodiscard]] constexpr int compare(StringView other) const
{
size_t rlen = min(length(), other.length());
int c = (rlen != 0) ? __builtin_memcmp(m_characters, other.m_characters, rlen) : 0;
if (m_characters == nullptr)
return other.m_characters ? -1 : 0;
if (other.m_characters == nullptr)
return 1;
size_t rlen = min(m_length, other.m_length);
int c = __builtin_memcmp(m_characters, other.m_characters, rlen);
if (c == 0) {
if (length() < other.length())
return -1;

View file

@ -42,10 +42,7 @@ TEST_CASE(construct_contents)
TEST_CASE(equal)
{
// FIXME: Enable this as soon as it's fixed.
#if 0
EXPECT_NE(String::empty(), String {});
#endif
}
TEST_CASE(compare)