summaryrefslogtreecommitdiff
path: root/AK/URL.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'AK/URL.cpp')
-rw-r--r--AK/URL.cpp54
1 files changed, 51 insertions, 3 deletions
diff --git a/AK/URL.cpp b/AK/URL.cpp
index 8c77031b88..7e690ff68b 100644
--- a/AK/URL.cpp
+++ b/AK/URL.cpp
@@ -54,6 +54,8 @@ bool URL::parse(const StringView& string)
InPath,
InQuery,
InFragment,
+ InDataMimeType,
+ InDataPayload,
};
Vector<char, 256> buffer;
@@ -75,30 +77,39 @@ bool URL::parse(const StringView& string)
while (index < string.length()) {
switch (state) {
- case State::InProtocol:
+ case State::InProtocol: {
if (is_valid_protocol_character(peek())) {
buffer.append(consume());
continue;
}
if (consume() != ':')
return false;
+
+ m_protocol = String::copy(buffer);
+
+ if (m_protocol == "data") {
+ buffer.clear();
+ state = State::InDataMimeType;
+ continue;
+ }
+
if (consume() != '/')
return false;
if (consume() != '/')
return false;
if (buffer.is_empty())
return false;
- m_protocol = String::copy(buffer);
if (m_protocol == "http")
m_port = 80;
else if (m_protocol == "https")
m_port = 443;
- buffer.clear();
if (m_protocol == "file")
state = State::InPath;
else
state = State::InHostname;
+ buffer.clear();
continue;
+ }
case State::InHostname:
if (is_valid_hostname_character(peek())) {
buffer.append(consume());
@@ -160,6 +171,41 @@ bool URL::parse(const StringView& string)
case State::InFragment:
buffer.append(consume());
continue;
+ case State::InDataMimeType: {
+ if (peek() != ';' && peek() != ',') {
+ buffer.append(consume());
+ continue;
+ }
+
+ m_data_mime_type = String::copy(buffer);
+ buffer.clear();
+
+ if (peek() == ';') {
+ consume();
+ if (consume() != 'b')
+ return false;
+ if (consume() != 'a')
+ return false;
+ if (consume() != 's')
+ return false;
+ if (consume() != 'e')
+ return false;
+ if (consume() != '6')
+ return false;
+ if (consume() != '4')
+ return false;
+ m_data_payload_is_base64 = true;
+ }
+
+ if (consume() != ',')
+ return false;
+
+ state = State::InDataPayload;
+ break;
+ }
+ case State::InDataPayload:
+ buffer.append(consume());
+ break;
}
}
if (state == State::InHostname) {
@@ -177,6 +223,8 @@ bool URL::parse(const StringView& string)
m_query = String::copy(buffer);
if (state == State::InFragment)
m_fragment = String::copy(buffer);
+ if (state == State::InDataPayload)
+ m_data_payload = String::copy(buffer);
if (m_query.is_null())
m_query = "";
if (m_fragment.is_null())