diff options
author | Andreas Kling <kling@serenityos.org> | 2021-04-22 00:00:06 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-04-22 00:00:59 +0200 |
commit | 385714802813e2a0f9287922647966e654850ab5 (patch) | |
tree | e9c9abf7ed2569b6bad12d8e73f4c5c94b5e6a59 | |
parent | edf0b14e230d5f39ecf1d1be08435e1c9d7a78c3 (diff) | |
download | serenity-385714802813e2a0f9287922647966e654850ab5.zip |
LibWeb+Base: Use AK::SourceGenerator for error pages
Instead of storing a format string in a file, let's be reasonable
and use SourceGenerator's template functionality. :^)
-rw-r--r-- | Base/res/html/error.html | 4 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Loader/FrameLoader.cpp | 14 |
2 files changed, 9 insertions, 9 deletions
diff --git a/Base/res/html/error.html b/Base/res/html/error.html index 8b06ed12a8..c9d254c81d 100644 --- a/Base/res/html/error.html +++ b/Base/res/html/error.html @@ -14,8 +14,8 @@ <body> <header> <img src="file:///res/icons/32x32/msgbox-warning.png" alt="Warning" width="24" height="24"> - <h1>Failed to load {}</h1> + <h1>Failed to load @failed_url@</h1> </header> - <p>Error: {}</p> + <p>Error: @error@</p> </body> </html> diff --git a/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp b/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp index d547580117..147bafa74b 100644 --- a/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp +++ b/Userland/Libraries/LibWeb/Loader/FrameLoader.cpp @@ -26,6 +26,7 @@ #include <AK/Debug.h> #include <AK/LexicalPath.h> +#include <AK/SourceGenerator.h> #include <LibGemini/Document.h> #include <LibGfx/ImageDecoder.h> #include <LibMarkdown/Document.h> @@ -226,13 +227,12 @@ void FrameLoader::load_error_page(const URL& failed_url, const String& error) error_page_url, [this, failed_url, error](auto data, auto&, auto) { VERIFY(!data.is_null()); -#pragma GCC diagnostic ignored "-Wformat-nonliteral" - auto html = String::formatted( - data, - escape_html_entities(failed_url.to_string()), - escape_html_entities(error)); -#pragma GCC diagnostic pop - auto document = HTML::parse_html_document(html, failed_url, "utf-8"); + StringBuilder builder; + SourceGenerator generator { builder }; + generator.set("failed_url", failed_url.to_string()); + generator.set("error", error); + generator.append(data); + auto document = HTML::parse_html_document(generator.as_string_view(), failed_url, "utf-8"); VERIFY(document); frame().set_document(document); }, |