mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 20:15:17 +00:00
LibWeb: Tolerate quoted HTTP Content-Type encodings
This commit is contained in:
parent
edf0aacda4
commit
eb33021d65
Notes:
sideshowbarker
2024-07-19 05:22:31 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/eb33021d65b
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)
|
||||
{
|
||||
auto offset = content_type.index_of("charset=");
|
||||
if (offset.has_value())
|
||||
return content_type.substring(offset.value() + 8, content_type.length() - offset.value() - 8).to_lowercase();
|
||||
if (offset.has_value()) {
|
||||
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";
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue