mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 15:48:12 +00:00
AK: Parse query and fragment in URL::parse()
This commit is contained in:
parent
21a61b276b
commit
c8d0a2eb3c
2 changed files with 90 additions and 3 deletions
34
AK/URL.cpp
34
AK/URL.cpp
|
@ -52,6 +52,8 @@ bool URL::parse(const StringView& string)
|
|||
InHostname,
|
||||
InPort,
|
||||
InPath,
|
||||
InQuery,
|
||||
InFragment,
|
||||
};
|
||||
|
||||
Vector<char, 256> buffer;
|
||||
|
@ -136,6 +138,26 @@ bool URL::parse(const StringView& string)
|
|||
}
|
||||
return false;
|
||||
case State::InPath:
|
||||
if (peek() == '?' || peek() == '#') {
|
||||
m_path = String::copy(buffer);
|
||||
buffer.clear();
|
||||
state = peek() == '?' ? State::InQuery : State::InFragment;
|
||||
consume();
|
||||
continue;
|
||||
}
|
||||
buffer.append(consume());
|
||||
continue;
|
||||
case State::InQuery:
|
||||
if (peek() == '#') {
|
||||
m_query = String::copy(buffer);
|
||||
buffer.clear();
|
||||
consume();
|
||||
state = State::InFragment;
|
||||
continue;
|
||||
}
|
||||
buffer.append(consume());
|
||||
continue;
|
||||
case State::InFragment:
|
||||
buffer.append(consume());
|
||||
continue;
|
||||
}
|
||||
|
@ -146,9 +168,17 @@ bool URL::parse(const StringView& string)
|
|||
return false;
|
||||
m_host = String::copy(buffer);
|
||||
m_path = "/";
|
||||
return true;
|
||||
}
|
||||
m_path = String::copy(buffer);
|
||||
if (state == State::InPath)
|
||||
m_path = String::copy(buffer);
|
||||
if (state == State::InQuery)
|
||||
m_query = String::copy(buffer);
|
||||
if (state == State::InFragment)
|
||||
m_fragment = String::copy(buffer);
|
||||
if (m_query.is_null())
|
||||
m_query = "";
|
||||
if (m_fragment.is_null())
|
||||
m_fragment = "";
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue