mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 04:08:11 +00:00
LibWeb: Tolerate quoted HTTP Content-Type encodings
This commit is contained in:
parent
edf0aacda4
commit
eb33021d65
1 changed files with 8 additions and 2 deletions
|
@ -62,8 +62,14 @@ void Resource::for_each_client(Function<void(ResourceClient&)> callback)
|
||||||
String encoding_from_content_type(const String& content_type)
|
String encoding_from_content_type(const String& content_type)
|
||||||
{
|
{
|
||||||
auto offset = content_type.index_of("charset=");
|
auto offset = content_type.index_of("charset=");
|
||||||
if (offset.has_value())
|
if (offset.has_value()) {
|
||||||
return content_type.substring(offset.value() + 8, content_type.length() - offset.value() - 8).to_lowercase();
|
auto encoding = content_type.substring(offset.value() + 8, content_type.length() - offset.value() - 8).to_lowercase();
|
||||||
|
if (encoding.length() >= 2 && encoding.starts_with('"') && encoding.ends_with('"'))
|
||||||
|
return encoding.substring(1, encoding.length() - 2);
|
||||||
|
if (encoding.length() >= 2 && encoding.starts_with('\'') && encoding.ends_with('\''))
|
||||||
|
return encoding.substring(1, encoding.length() - 2);
|
||||||
|
return encoding;
|
||||||
|
}
|
||||||
|
|
||||||
return "utf-8";
|
return "utf-8";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue