mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-29 12:19:54 +00:00
LibWeb: Only use code unit length for is_code_unit_prefix
Fixes a crash in the included test.
This commit is contained in:
parent
1cd09724f1
commit
74334ea1ce
Notes:
github-actions[bot]
2025-05-12 09:21:40 +00:00
Author: https://github.com/shannonbooth
Commit: 74334ea1ce
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4702
Reviewed-by: https://github.com/gmta ✅
3 changed files with 55 additions and 7 deletions
45
Tests/LibWeb/TestStrings.cpp
Normal file
45
Tests/LibWeb/TestStrings.cpp
Normal file
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* Copyright (c) 2025, Shannon Booth <shannon@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibTest/TestCase.h>
|
||||
#include <LibWeb/Infra/Strings.h>
|
||||
|
||||
TEST_CASE(is_code_unit_prefix)
|
||||
{
|
||||
|
||||
// Basic prefix match
|
||||
EXPECT(Web::Infra::is_code_unit_prefix("abc"sv, "abcde"sv));
|
||||
|
||||
// Exact match
|
||||
EXPECT(Web::Infra::is_code_unit_prefix("abc"sv, "abc"sv));
|
||||
|
||||
// Empty prefix
|
||||
EXPECT(Web::Infra::is_code_unit_prefix(""sv, "abc"sv));
|
||||
|
||||
// Empty input string
|
||||
EXPECT(!Web::Infra::is_code_unit_prefix("abc"sv, ""sv));
|
||||
|
||||
// Both strings empty
|
||||
EXPECT(Web::Infra::is_code_unit_prefix(""sv, ""sv));
|
||||
|
||||
// Prefix longer than input string
|
||||
EXPECT(!Web::Infra::is_code_unit_prefix("abcdef"sv, "abc"sv));
|
||||
|
||||
// Non-ASCII characters
|
||||
EXPECT(Web::Infra::is_code_unit_prefix("こんにちは"sv, "こんにちは世界"sv));
|
||||
EXPECT(!Web::Infra::is_code_unit_prefix("世界"sv, "こんにちは世界"sv));
|
||||
|
||||
EXPECT(Web::Infra::is_code_unit_prefix("こ"sv, "こん"sv));
|
||||
EXPECT(!Web::Infra::is_code_unit_prefix("こん"sv, "こ"sv));
|
||||
|
||||
// Special characters
|
||||
EXPECT(Web::Infra::is_code_unit_prefix("!@#"sv, "!@#$%^"sv));
|
||||
EXPECT(!Web::Infra::is_code_unit_prefix("!@#$"sv, "!@#"sv));
|
||||
|
||||
// Case sensitivity
|
||||
EXPECT(!Web::Infra::is_code_unit_prefix("abc"sv, "ABC"sv));
|
||||
EXPECT(!Web::Infra::is_code_unit_prefix("ABC"sv, "abc"sv));
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue