mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 18:02:05 -05:00
LibWeb: Ignore invalid encodings in Content-Type headers
This commit is contained in:
parent
681fac07ed
commit
1d55437a76
1 changed files with 8 additions and 2 deletions
|
@ -8,6 +8,7 @@
|
|||
#include <AK/Function.h>
|
||||
#include <LibCore/EventLoop.h>
|
||||
#include <LibCore/MimeData.h>
|
||||
#include <LibTextCodec/Decoder.h>
|
||||
#include <LibWeb/HTML/HTMLImageElement.h>
|
||||
#include <LibWeb/Loader/Resource.h>
|
||||
|
||||
|
@ -64,6 +65,11 @@ static String mime_type_from_content_type(const String& content_type)
|
|||
return content_type;
|
||||
}
|
||||
|
||||
static bool is_valid_encoding(String const& encoding)
|
||||
{
|
||||
return TextCodec::decoder_for(encoding);
|
||||
}
|
||||
|
||||
void Resource::did_load(Badge<ResourceLoader>, ReadonlyBytes data, const HashMap<String, String, CaseInsensitiveStringTraits>& headers, Optional<u32> status_code)
|
||||
{
|
||||
VERIFY(!m_loaded);
|
||||
|
@ -98,8 +104,8 @@ void Resource::did_load(Badge<ResourceLoader>, ReadonlyBytes data, const HashMap
|
|||
m_encoding = {};
|
||||
if (content_type.has_value()) {
|
||||
auto encoding = encoding_from_content_type(content_type.value());
|
||||
if (encoding.has_value()) {
|
||||
dbgln_if(RESOURCE_DEBUG, "Set encoding '{}' from Content-Type", encoding.has_value());
|
||||
if (encoding.has_value() && is_valid_encoding(encoding.value())) {
|
||||
dbgln_if(RESOURCE_DEBUG, "Set encoding '{}' from Content-Type", encoding.value());
|
||||
m_encoding = encoding.value();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue