mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 14:47:46 +00:00
LibWeb: Validate MimeType(String, String)
arguments correctly
This commit correctly validates the `type` and `subtype` arguments, instead of checking for http quoted code points, by following how the spec's MIME type parsing algorithm would validate a MIME type's type and subtype. It also uses the move-assigned member variables instead of the arguments within the constructor body (as using the arguments at this point will lead to undesired behavior).
This commit is contained in:
parent
2248d85894
commit
6b37095ffd
1 changed files with 13 additions and 12 deletions
|
@ -39,18 +39,6 @@ static bool contains_only_http_quoted_string_token_code_points(StringView string
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
MimeType::MimeType(String type, String subtype)
|
|
||||||
: m_type(move(type))
|
|
||||||
, m_subtype(move(subtype))
|
|
||||||
{
|
|
||||||
// https://mimesniff.spec.whatwg.org/#parameters
|
|
||||||
// A MIME type’s parameters is an ordered map whose keys are ASCII strings and values are strings limited to HTTP quoted-string token code points.
|
|
||||||
VERIFY(contains_only_http_quoted_string_token_code_points(type));
|
|
||||||
VERIFY(contains_only_http_quoted_string_token_code_points(subtype));
|
|
||||||
}
|
|
||||||
|
|
||||||
MimeType::~MimeType() = default;
|
|
||||||
|
|
||||||
static bool contains_only_http_token_code_points(StringView string)
|
static bool contains_only_http_token_code_points(StringView string)
|
||||||
{
|
{
|
||||||
// https://mimesniff.spec.whatwg.org/#http-token-code-point
|
// https://mimesniff.spec.whatwg.org/#http-token-code-point
|
||||||
|
@ -64,6 +52,19 @@ static bool contains_only_http_token_code_points(StringView string)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MimeType::MimeType(String type, String subtype)
|
||||||
|
: m_type(move(type))
|
||||||
|
, m_subtype(move(subtype))
|
||||||
|
{
|
||||||
|
// NOTE: type and subtype are expected to be non-empty and contain only
|
||||||
|
// http token code points in the MIME type parsing algorithm. That's
|
||||||
|
// why we are performing the same checks here.
|
||||||
|
VERIFY(!m_type.is_empty() && contains_only_http_token_code_points(m_type));
|
||||||
|
VERIFY(!m_subtype.is_empty() && contains_only_http_token_code_points(m_subtype));
|
||||||
|
}
|
||||||
|
|
||||||
|
MimeType::~MimeType() = default;
|
||||||
|
|
||||||
ErrorOr<MimeType> MimeType::create(String type, String value)
|
ErrorOr<MimeType> MimeType::create(String type, String value)
|
||||||
{
|
{
|
||||||
auto mime_type = MimeType { move(type), move(value) };
|
auto mime_type = MimeType { move(type), move(value) };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue