mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 08:34:57 +00:00
AK: Fix StringView::find_last_of for one-character views
The find_last_of implementations were breaking out of the search loop too early for single-character string views. This caused a crash in CookieJar setting a cookie on google.com - CookieJar::default_path knew there was at least one "/" in a string view, but find_last_of returned nullopt, so dereferencing the optional caused a crash. Fixes #6273
This commit is contained in:
parent
d363ed8872
commit
3f4e90f32b
2 changed files with 12 additions and 6 deletions
|
@ -294,20 +294,20 @@ Optional<size_t> StringView::find_first_of(const StringView& view) const
|
|||
|
||||
Optional<size_t> StringView::find_last_of(char c) const
|
||||
{
|
||||
for (size_t pos = m_length; --pos > 0;) {
|
||||
if (m_characters[pos] == c)
|
||||
return pos;
|
||||
for (size_t pos = m_length; pos != 0; --pos) {
|
||||
if (m_characters[pos - 1] == c)
|
||||
return pos - 1;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
Optional<size_t> StringView::find_last_of(const StringView& view) const
|
||||
{
|
||||
for (size_t pos = m_length - 1; --pos > 0;) {
|
||||
char c = m_characters[pos];
|
||||
for (size_t pos = m_length; pos != 0; --pos) {
|
||||
char c = m_characters[pos - 1];
|
||||
for (char view_char : view) {
|
||||
if (c == view_char)
|
||||
return pos;
|
||||
return pos - 1;
|
||||
}
|
||||
}
|
||||
return {};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue