From 56dbe58bbb97a0c7d5416ce16094ccbbf2efe0a6 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 10 May 2020 11:11:48 +0200 Subject: [PATCH] AK: Add support for about: URLs --- AK/Tests/TestURL.cpp | 9 +++++++++ AK/URL.cpp | 12 ++++++++++++ 2 files changed, 21 insertions(+) diff --git a/AK/Tests/TestURL.cpp b/AK/Tests/TestURL.cpp index 53251a3cca1..380c15ccfdc 100644 --- a/AK/Tests/TestURL.cpp +++ b/AK/Tests/TestURL.cpp @@ -148,4 +148,13 @@ TEST_CASE(file_url_without_hostname) EXPECT_EQ(url.to_string(), "file:///my/file"); } +TEST_CASE(about_url) +{ + URL url("about:blank"); + EXPECT_EQ(url.is_valid(), true); + EXPECT_EQ(url.protocol(), "about"); + EXPECT_EQ(url.path(), "blank"); + EXPECT_EQ(url.to_string(), "about:blank"); +} + TEST_MAIN(URL) diff --git a/AK/URL.cpp b/AK/URL.cpp index 1f84604202b..688d5446fa8 100644 --- a/AK/URL.cpp +++ b/AK/URL.cpp @@ -93,6 +93,12 @@ bool URL::parse(const StringView& string) continue; } + if (m_protocol == "about") { + buffer.clear(); + state = State::InPath; + continue; + } + if (consume() != '/') return false; if (consume() != '/') @@ -245,6 +251,12 @@ String URL::to_string() const StringBuilder builder; builder.append(m_protocol); + if (m_protocol == "about") { + builder.append(':'); + builder.append(m_path); + return builder.to_string(); + } + if (m_protocol == "data") { builder.append(':'); builder.append(m_data_mime_type);