Skip to content

Commit

Permalink
Merge isXMLSpace() into isJSONOrHTTPWhitespace()
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=255872
rdar://108738795

Reviewed by Darin Adler.

It turns out that JSON, HTTP, and XML all use the same whitespace
definition, so let's make them share it. Also correct an existing
comment for that function as \v is not part of isASCIIWhitespace(), but
\f is.

Furthermore, remove the "optimization" from these whitespace functions
per a comment from Chris Dumez at
#13080 (comment):

> Just verified out of curiosity and llvm does generate the same code
> with -O2 (tried both arm64 and x86_64):
>
> isXMLSpace1(char):                       // @isXMLSpace1(char)
>         mov     x8, #9728                       // =0x2600
>         and     w9, w0, #0xff
>         movk    x8, #1, lsl #32
>         cmp     w9, #33
>         cset    w9, lo
>         lsr     x8, x8, x0
>         and     w0, w9, w8
>         ret
> isXMLSpace2(char):                       // @isXMLSpace2(char)
>         mov     x8, #9728                       // =0x2600
>         and     w9, w0, #0xff
>         movk    x8, #1, lsl #32
>         cmp     w9, #33
>         cset    w9, lo
>         lsr     x8, x8, x0
>         and     w0, w9, w8
>         ret
>
> Ahmad-S792 Let's simplify the code then.

* Source/WTF/wtf/ASCIICType.h:
(WTF::isASCIIWhitespace):
(WTF::isJSONOrHTTPOrXMLWhitespace):
(WTF::isJSONOrHTTPWhitespace): Deleted.
* Source/WTF/wtf/JSONValues.cpp:
(WTF::JSONImpl::Value::parseJSON):
* Source/WTF/wtf/text/StringToIntegerConversion.h:
* Source/WebCore/Modules/cache/DOMCache.cpp:
(WebCore::hasResponseVaryStarHeaderValue):
* Source/WebCore/Modules/cache/DOMCacheEngine.cpp:
(WebCore::DOMCacheEngine::queryCacheMatch):
* Source/WebCore/Modules/fetch/FetchBodyConsumer.cpp:
(WebCore::parseParameters):
(WebCore::parseMIMEType):
(WebCore::FetchBodyConsumer::packageFormData):
* Source/WebCore/Modules/fetch/FetchHeaders.cpp:
(WebCore::canWriteHeader):
(WebCore::appendToHeaderMap):
(WebCore::FetchHeaders::set):
(WebCore::FetchHeaders::filterAndFill):
* Source/WebCore/mathml/MathMLPresentationElement.cpp:
(WebCore::MathMLPresentationElement::parseMathMLLength):
* Source/WebCore/mathml/MathMLTokenElement.cpp:
(WebCore::MathMLTokenElement::convertToSingleCodePoint):
* Source/WebCore/page/csp/ContentSecurityPolicyDirectiveList.cpp:
(WebCore::ContentSecurityPolicyDirectiveList::parse):
* Source/WebCore/platform/ReferrerPolicy.cpp:
(WebCore::parseReferrerPolicy):
* Source/WebCore/platform/network/DataURLDecoder.cpp:
(WebCore::DataURLDecoder::DecodeTask::process):
* Source/WebCore/platform/network/HTTPParsers.cpp:
(WebCore::parseContentTypeOptionsHeader):
(WebCore::parseClearSiteDataHeader):
(WebCore::parseRange):
(WebCore::parseCrossOriginResourcePolicyHeader):
* Source/WebCore/platform/network/HTTPParsers.h:
(WebCore::addToAccessControlAllowList):
* Source/WebCore/platform/network/ParsedContentType.cpp:
(WebCore::skipSpaces):
(WebCore::parseToken):
(WebCore::ParsedContentType::create):
(WebCore::ParsedContentType::setContentType):
* Source/WebCore/platform/network/ResourceResponseBase.cpp:
(WebCore::ResourceResponseBase::containsInvalidHTTPHeaders const):
* Source/WebCore/platform/network/TimingAllowOrigin.cpp:
(WebCore::passesTimingAllowOriginCheck):
* Source/WebCore/xml/XMLHttpRequest.cpp:
(WebCore::XMLHttpRequest::setRequestHeader):
* Source/WebCore/xml/XPathFunctions.cpp:
(WebCore::XPath::FunNormalizeSpace::evaluate const):
* Source/WebCore/xml/XPathParser.cpp:
(WebCore::XPath::Parser::skipWS):
* Source/WebCore/xml/XPathUtil.cpp:
(WebCore::XPath::isXMLSpace): Deleted.
* Source/WebCore/xml/XPathUtil.h:
* Source/WebKit/NetworkProcess/cache/CacheStorageEngineCache.cpp:
(WebKit::CacheStorage::updateVaryInformation):
* Source/WebKit/NetworkProcess/soup/WebSocketTaskSoup.cpp:
(WebKit::WebSocketTask::WebSocketTask):
* Source/WebKit/NetworkProcess/storage/CacheStorageRecord.h:
(WebKit::CacheStorageRecordInformation::updateVaryHeaders):
* Source/WebKit/WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::shouldSkipDecidePolicyForResponse const):

Canonical link: https://commits.webkit.org/266253@main
  • Loading branch information
annevk committed Jul 24, 2023
1 parent cc626f3 commit f70bfc7
Show file tree
Hide file tree
Showing 26 changed files with 50 additions and 81 deletions.
42 changes: 10 additions & 32 deletions Source/WTF/wtf/ASCIICType.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,46 +141,24 @@ template<typename CharacterType> constexpr bool isTabOrSpace(CharacterType chara
// Infra's "ASCII whitespace" <https://infra.spec.whatwg.org/#ascii-whitespace>
template<typename CharacterType> constexpr bool isASCIIWhitespace(CharacterType character)
{
// Histogram from Apple's page load test combined with some ad hoc browsing some other test suites.
//
// 82%: 216330 non-space characters, all > U+0020
// 11%: 30017 plain space characters, U+0020
// 5%: 12099 newline characters, U+000A
// 2%: 5346 tab characters, U+0009
//
// No other characters seen. No U+000C or U+000D, and no other control characters.
// Accordingly, we check for non-spaces first, then space, then newline, then tab, then the other characters.

return character <= ' ' && (character == ' ' || character == '\n' || character == '\t' || character == '\r' || character == '\f');
return character == ' ' || character == '\n' || character == '\t' || character == '\r' || character == '\f';
}

template<typename CharacterType> constexpr bool isJSONOrHTTPWhitespace(CharacterType character)
template<typename CharacterType> constexpr bool isASCIIWhitespaceWithoutFF(CharacterType character)
{
// This is different from isASCIIWhitespace: JSON does not accept \v as a space.
// ECMA-404 specifies the followings.
// This is different from isASCIIWhitespace: JSON/HTTP/XML do not accept \f as a whitespace.
// ECMA-404 specifies the following:
// > Whitespace is any sequence of one or more of the following code points:
// > character tabulation (U+0009), line feed (U+000A), carriage return (U+000D), and space (U+0020).
//
// Also, this definition is the same to HTTP whitespace.
// This matches HTTP whitespace:
// https://fetch.spec.whatwg.org/#http-whitespace-byte
return character <= ' ' && (character == ' ' || character == '\n' || character == '\t' || character == '\r');
//
// And XML whitespace:
// https://www.w3.org/TR/2008/REC-xml-20081126/#NT-S
return character == ' ' || character == '\n' || character == '\t' || character == '\r';
}

/*
Statistics from a run of Apple's page load test for callers of isUnicodeCompatibleASCIIWhitespace:
character count
--------- -----
non-spaces 689383
20 space 294720
0A \n 89059
09 \t 28320
0D \r 0
0C \f 0
0B \v 0
As these are compatible with those for isASCIIWhitespace we let that do most of the work.
*/
template<typename CharacterType> constexpr bool isUnicodeCompatibleASCIIWhitespace(CharacterType character)
{
return isASCIIWhitespace(character) || character == '\v';
Expand Down Expand Up @@ -288,7 +266,7 @@ using WTF::isASCIIOctalDigit;
using WTF::isASCIIPrintable;
using WTF::isTabOrSpace;
using WTF::isASCIIWhitespace;
using WTF::isJSONOrHTTPWhitespace;
using WTF::isASCIIWhitespaceWithoutFF;
using WTF::isUnicodeCompatibleASCIIWhitespace;
using WTF::isASCIIUpper;
using WTF::isNotASCIIWhitespace;
Expand Down
4 changes: 2 additions & 2 deletions Source/WTF/wtf/JSONValues.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ bool parseStringToken(const CodeUnit* start, const CodeUnit* end, const CodeUnit
template<typename CodeUnit>
Token parseToken(const CodeUnit* start, const CodeUnit* end, const CodeUnit** tokenStart, const CodeUnit** tokenEnd)
{
while (start < end && isJSONOrHTTPWhitespace(*start))
while (start < end && isASCIIWhitespaceWithoutFF(*start))
++start;

if (start == end)
Expand Down Expand Up @@ -524,7 +524,7 @@ RefPtr<Value> Value::parseJSON(StringView json)
if (!begin)
return false;
for (const auto* it = begin; it < end; it++) {
if (!isJSONOrHTTPWhitespace(*it))
if (!isASCIIWhitespaceWithoutFF(*it))
return true;
}
return false;
Expand Down
2 changes: 1 addition & 1 deletion Source/WTF/wtf/text/StringToIntegerConversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace WTF {
// The parseIntegerAllowingTrailingJunk function template is like parseInteger, but allows any characters after the integer.

// FIXME: Should we add a version that does not allow "+"?
// FIXME: Should we add a version that allows other definitions of spaces, like isASCIIWhitespace or isJSONOrHTTPWhitespace?
// FIXME: Should we add a version that allows other definitions of spaces, like isASCIIWhitespace or isASCIIWhitespaceWithoutFF?
// FIXME: Should we add a version that does not allow leading and trailing spaces?

template<typename IntegralType> std::optional<IntegralType> parseInteger(StringView, uint8_t base = 10);
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/Modules/cache/DOMCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ static inline bool hasResponseVaryStarHeaderValue(const FetchResponse& response)
auto varyValue = response.headers().internalHeaders().get(WebCore::HTTPHeaderName::Vary);
bool hasStar = false;
varyValue.split(',', [&](StringView view) {
if (!hasStar && view.trim(isJSONOrHTTPWhitespace<UChar>) == "*"_s)
if (!hasStar && view.trim(isASCIIWhitespaceWithoutFF<UChar>) == "*"_s)
hasStar = true;
});
return hasStar;
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/Modules/cache/DOMCacheEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ bool queryCacheMatch(const ResourceRequest& request, const ResourceRequest& cach
varyValue.split(',', [&](StringView view) {
if (isVarying)
return;
auto nameView = view.trim(isJSONOrHTTPWhitespace<UChar>);
auto nameView = view.trim(isASCIIWhitespaceWithoutFF<UChar>);
if (nameView == "*"_s) {
isVarying = true;
return;
Expand Down
8 changes: 4 additions & 4 deletions Source/WebCore/Modules/fetch/FetchBodyConsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ static HashMap<String, String> parseParameters(StringView input, size_t position
size_t valueBegin = position;
while (position < input.length() && input[position] != ';')
position++;
parameterValue = input.substring(valueBegin, position - valueBegin).trim(isJSONOrHTTPWhitespace<UChar>);
parameterValue = input.substring(valueBegin, position - valueBegin).trim(isASCIIWhitespaceWithoutFF<UChar>);
}

if (parameterName.length()
Expand All @@ -110,7 +110,7 @@ static HashMap<String, String> parseParameters(StringView input, size_t position
// https://mimesniff.spec.whatwg.org/#parsing-a-mime-type
static std::optional<MimeType> parseMIMEType(const String& contentType)
{
String input = contentType.trim(isJSONOrHTTPWhitespace<UChar>);
String input = contentType.trim(isASCIIWhitespaceWithoutFF<UChar>);
size_t slashIndex = input.find('/');
if (slashIndex == notFound)
return std::nullopt;
Expand All @@ -120,7 +120,7 @@ static std::optional<MimeType> parseMIMEType(const String& contentType)
return std::nullopt;

size_t semicolonIndex = input.find(';', slashIndex);
String subtype = input.substring(slashIndex + 1, semicolonIndex - slashIndex - 1).trim(isJSONOrHTTPWhitespace<UChar>);
String subtype = input.substring(slashIndex + 1, semicolonIndex - slashIndex - 1).trim(isASCIIWhitespaceWithoutFF<UChar>);
if (!subtype.length() || !isValidHTTPToken(subtype))
return std::nullopt;

Expand Down Expand Up @@ -175,7 +175,7 @@ RefPtr<DOMFormData> FetchBodyConsumer::packageFormData(ScriptExecutionContext* c
size_t contentTypeBegin = header.find(contentTypeCharacters);
if (contentTypeBegin != notFound) {
size_t contentTypeEnd = header.find("\r\n"_s, contentTypeBegin);
contentType = StringView(header).substring(contentTypeBegin + contentTypePrefixLength, contentTypeEnd - contentTypeBegin - contentTypePrefixLength).trim(isJSONOrHTTPWhitespace<UChar>).toString();
contentType = StringView(header).substring(contentTypeBegin + contentTypePrefixLength, contentTypeEnd - contentTypeBegin - contentTypePrefixLength).trim(isASCIIWhitespaceWithoutFF<UChar>).toString();
}

form.append(name, File::create(context, Blob::create(context, Vector { bodyBegin, bodyLength }, Blob::normalizedContentType(contentType)).get(), filename).get(), filename);
Expand Down
10 changes: 5 additions & 5 deletions Source/WebCore/Modules/fetch/FetchHeaders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static ExceptionOr<bool> canWriteHeader(const String& name, const String& value,
{
if (!isValidHTTPToken(name))
return Exception { TypeError, makeString("Invalid header name: '", name, "'") };
ASSERT(value.isEmpty() || (!isJSONOrHTTPWhitespace(value[0]) && !isJSONOrHTTPWhitespace(value[value.length() - 1])));
ASSERT(value.isEmpty() || (!isASCIIWhitespaceWithoutFF(value[0]) && !isASCIIWhitespaceWithoutFF(value[value.length() - 1])));
if (!isValidHTTPHeaderValue((value)))
return Exception { TypeError, makeString("Header '", name, "' has invalid value: '", value, "'") };
if (guard == FetchHeaders::Guard::Immutable)
Expand Down Expand Up @@ -72,7 +72,7 @@ static ExceptionOr<void> appendSetCookie(const String& value, Vector<String>& se

static ExceptionOr<void> appendToHeaderMap(const String& name, const String& value, HTTPHeaderMap& headers, Vector<String>& setCookieValues, FetchHeaders::Guard guard)
{
String normalizedValue = value.trim(isJSONOrHTTPWhitespace<UChar>);
String normalizedValue = value.trim(isASCIIWhitespaceWithoutFF<UChar>);
if (equalIgnoringASCIICase(name, "set-cookie"_s))
return appendSetCookie(normalizedValue, setCookieValues, guard);

Expand All @@ -95,7 +95,7 @@ static ExceptionOr<void> appendToHeaderMap(const String& name, const String& val
static ExceptionOr<void> appendToHeaderMap(const HTTPHeaderMap::HTTPHeaderMapConstIterator::KeyValue& header, HTTPHeaderMap& headers, FetchHeaders::Guard guard)
{
ASSERT(!equalIgnoringASCIICase(header.key, "set-cookie"_s));
String normalizedValue = header.value.trim(isJSONOrHTTPWhitespace<UChar>);
String normalizedValue = header.value.trim(isASCIIWhitespaceWithoutFF<UChar>);
auto canWriteResult = canWriteHeader(header.key, normalizedValue, header.value, guard);
if (canWriteResult.hasException())
return canWriteResult.releaseException();
Expand Down Expand Up @@ -239,7 +239,7 @@ ExceptionOr<bool> FetchHeaders::has(const String& name) const

ExceptionOr<void> FetchHeaders::set(const String& name, const String& value)
{
String normalizedValue = value.trim(isJSONOrHTTPWhitespace<UChar>);
String normalizedValue = value.trim(isASCIIWhitespaceWithoutFF<UChar>);
auto canWriteResult = canWriteHeader(name, normalizedValue, normalizedValue, m_guard);
if (canWriteResult.hasException())
return canWriteResult.releaseException();
Expand All @@ -262,7 +262,7 @@ ExceptionOr<void> FetchHeaders::set(const String& name, const String& value)
void FetchHeaders::filterAndFill(const HTTPHeaderMap& headers, Guard guard)
{
for (auto& header : headers) {
String normalizedValue = header.value.trim(isJSONOrHTTPWhitespace<UChar>);
String normalizedValue = header.value.trim(isASCIIWhitespaceWithoutFF<UChar>);
auto canWriteResult = canWriteHeader(header.key, normalizedValue, header.value, guard);
if (canWriteResult.hasException())
continue;
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/mathml/MathMLPresentationElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ MathMLElement::Length MathMLPresentationElement::parseMathMLLength(const String&

// We first skip whitespace from both ends of the string.
StringView stringView = string;
StringView trimmedLength = stringView.trim(isJSONOrHTTPWhitespace<UChar>);
StringView trimmedLength = stringView.trim(isASCIIWhitespaceWithoutFF<UChar>);

if (trimmedLength.isEmpty())
return Length();
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/mathml/MathMLTokenElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ bool MathMLTokenElement::childShouldCreateRenderer(const Node& child) const

std::optional<UChar32> MathMLTokenElement::convertToSingleCodePoint(StringView string)
{
auto codePoints = string.trim(isJSONOrHTTPWhitespace<UChar>).codePoints();
auto codePoints = string.trim(isASCIIWhitespaceWithoutFF<UChar>).codePoints();
auto iterator = codePoints.begin();
if (iterator == codePoints.end())
return std::nullopt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ void ContentSecurityPolicyDirectiveList::parse(const String& policy, ContentSecu
// A meta tag delievered CSP could contain invalid HTTP header values depending on how it was formatted in the document.
// We want to store the CSP as a valid HTTP header for e.g. blob URL inheritance.
if (policyFrom == ContentSecurityPolicy::PolicyFrom::HTTPEquivMeta) {
m_header = policy.trim(isJSONOrHTTPWhitespace<UChar>).removeCharacters([](auto c) {
m_header = policy.trim(isASCIIWhitespaceWithoutFF<UChar>).removeCharacters([](auto c) {
return c == 0x00 || c == '\r' || c == '\n';
});
} else
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/platform/ReferrerPolicy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ std::optional<ReferrerPolicy> parseReferrerPolicy(StringView policyString, Refer
// Implementing https://www.w3.org/TR/2017/CR-referrer-policy-20170126/#parse-referrer-policy-from-header.
std::optional<ReferrerPolicy> result;
for (auto tokenView : policyString.split(',')) {
auto token = parseReferrerPolicyToken(tokenView.trim(isJSONOrHTTPWhitespace<UChar>), ShouldParseLegacyKeywords::No);
auto token = parseReferrerPolicyToken(tokenView.trim(isASCIIWhitespaceWithoutFF<UChar>), ShouldParseLegacyKeywords::No);
if (token && token.value() != ReferrerPolicy::EmptyString)
result = token.value();
}
Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/platform/network/DataURLDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,13 @@ struct DecodeTask {
// formatTypeStart might be at the begining of "base64" or "charset=...".
size_t formatTypeStart = mediaTypeEnd + 1;
auto formatType = header.substring(formatTypeStart, header.length() - formatTypeStart);
formatType = formatType.trim(isJSONOrHTTPWhitespace<UChar>);
formatType = formatType.trim(isASCIIWhitespaceWithoutFF<UChar>);

isBase64 = equalLettersIgnoringASCIICase(formatType, "base64"_s);

// If header does not end with "base64", mediaType should be the whole header.
auto mediaType = (isBase64 ? header.left(mediaTypeEnd) : header).toString();
mediaType = mediaType.trim(isJSONOrHTTPWhitespace<UChar>);
mediaType = mediaType.trim(isASCIIWhitespaceWithoutFF<UChar>);
if (mediaType.startsWith(';'))
mediaType = makeString("text/plain"_s, mediaType);

Expand Down
8 changes: 4 additions & 4 deletions Source/WebCore/platform/network/HTTPParsers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ XSSProtectionDisposition parseXSSProtectionHeader(const String& header, String&
ContentTypeOptionsDisposition parseContentTypeOptionsHeader(StringView header)
{
StringView leftToken = header.left(header.find(','));
if (equalLettersIgnoringASCIICase(leftToken.trim(isJSONOrHTTPWhitespace<UChar>), "nosniff"_s))
if (equalLettersIgnoringASCIICase(leftToken.trim(isASCIIWhitespaceWithoutFF<UChar>), "nosniff"_s))
return ContentTypeOptionsDisposition::Nosniff;
return ContentTypeOptionsDisposition::None;
}
Expand Down Expand Up @@ -595,7 +595,7 @@ OptionSet<ClearSiteDataValue> parseClearSiteDataHeader(const ResourceResponse& r
return result;

for (auto value : StringView(headerValue).split(',')) {
auto trimmedValue = value.trim(isJSONOrHTTPWhitespace<UChar>);
auto trimmedValue = value.trim(isASCIIWhitespaceWithoutFF<UChar>);
if (trimmedValue == "\"cache\""_s)
result.add(ClearSiteDataValue::Cache);
else if (trimmedValue == "\"cookies\""_s)
Expand Down Expand Up @@ -625,7 +625,7 @@ bool parseRange(StringView range, RangeAllowWhitespace allowWhitespace, long lon
if (!startsWithLettersIgnoringASCIICase(range, "bytes"_s))
return false;

auto byteRange = range.substring(bytesLength).trim(isJSONOrHTTPWhitespace<UChar>);
auto byteRange = range.substring(bytesLength).trim(isASCIIWhitespaceWithoutFF<UChar>);

if (!byteRange.startsWith('='))
return false;
Expand Down Expand Up @@ -991,7 +991,7 @@ bool isSafeMethod(const String& method)

CrossOriginResourcePolicy parseCrossOriginResourcePolicyHeader(StringView header)
{
auto trimmedHeader = header.trim(isJSONOrHTTPWhitespace<UChar>);
auto trimmedHeader = header.trim(isASCIIWhitespaceWithoutFF<UChar>);

if (trimmedHeader.isEmpty())
return CrossOriginResourcePolicy::None;
Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/platform/network/HTTPParsers.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,15 @@ bool addToAccessControlAllowList(const String& string, unsigned start, unsigned
return true;

// Skip white space from start.
while (start <= end && isJSONOrHTTPWhitespace((*stringImpl)[start]))
while (start <= end && isASCIIWhitespaceWithoutFF((*stringImpl)[start]))
++start;

// only white space
if (start > end)
return true;

// Skip white space from end.
while (end && isJSONOrHTTPWhitespace((*stringImpl)[end]))
while (end && isASCIIWhitespaceWithoutFF((*stringImpl)[end]))
--end;

auto token = string.substring(start, end - start + 1);
Expand Down
8 changes: 4 additions & 4 deletions Source/WebCore/platform/network/ParsedContentType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace WebCore {

static void skipSpaces(StringView input, unsigned& startIndex)
{
while (startIndex < input.length() && isJSONOrHTTPWhitespace(input[startIndex]))
while (startIndex < input.length() && isASCIIWhitespaceWithoutFF(input[startIndex]))
++startIndex;
}

Expand Down Expand Up @@ -78,7 +78,7 @@ static StringView parseToken(StringView input, unsigned& startIndex, CharacterMe
while (input[tokenEnd - 1] == ' ')
--tokenEnd;
} else {
while (isJSONOrHTTPWhitespace(input[tokenEnd - 1]))
while (isASCIIWhitespaceWithoutFF(input[tokenEnd - 1]))
--tokenEnd;
}
}
Expand Down Expand Up @@ -329,7 +329,7 @@ bool ParsedContentType::parseContentType(Mode mode)

std::optional<ParsedContentType> ParsedContentType::create(const String& contentType, Mode mode)
{
ParsedContentType parsedContentType(mode == Mode::Rfc2045 ? contentType : contentType.trim(isJSONOrHTTPWhitespace<UChar>));
ParsedContentType parsedContentType(mode == Mode::Rfc2045 ? contentType : contentType.trim(isASCIIWhitespaceWithoutFF<UChar>));
if (!parsedContentType.parseContentType(mode))
return std::nullopt;
return { WTFMove(parsedContentType) };
Expand Down Expand Up @@ -369,7 +369,7 @@ void ParsedContentType::setContentType(String&& contentRange, Mode mode)
{
m_mimeType = WTFMove(contentRange);
if (mode == Mode::MimeSniff)
m_mimeType = StringView(m_mimeType).trim(isJSONOrHTTPWhitespace<UChar>).convertToASCIILowercase();
m_mimeType = StringView(m_mimeType).trim(isASCIIWhitespaceWithoutFF<UChar>).convertToASCIILowercase();
else
m_mimeType = m_mimeType.trim(deprecatedIsSpaceOrNewline);
}
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/platform/network/ResourceResponseBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,7 @@ bool ResourceResponseBase::equalForWebKitLegacyChallengeComparison(const Resourc
bool ResourceResponseBase::containsInvalidHTTPHeaders() const
{
for (auto& header : httpHeaderFields()) {
if (!isValidHTTPHeaderValue(header.value.trim(isJSONOrHTTPWhitespace<UChar>)))
if (!isValidHTTPHeaderValue(header.value.trim(isASCIIWhitespaceWithoutFF<UChar>)))
return true;
}
return false;
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/platform/network/TimingAllowOrigin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ bool passesTimingAllowOriginCheck(const ResourceResponse& response, const Securi
const auto& timingAllowOriginString = response.httpHeaderField(HTTPHeaderName::TimingAllowOrigin);
const auto& securityOrigin = initiatorSecurityOrigin.toString();
for (auto originWithSpace : StringView(timingAllowOriginString).split(',')) {
auto origin = originWithSpace.trim(isJSONOrHTTPWhitespace<UChar>);
auto origin = originWithSpace.trim(isASCIIWhitespaceWithoutFF<UChar>);
if (origin == "*"_s || origin == securityOrigin)
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/xml/XMLHttpRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ ExceptionOr<void> XMLHttpRequest::setRequestHeader(const String& name, const Str
if (readyState() != OPENED || m_sendFlag)
return Exception { InvalidStateError };

String normalizedValue = value.trim(isJSONOrHTTPWhitespace<UChar>);
String normalizedValue = value.trim(isASCIIWhitespaceWithoutFF<UChar>);
if (!isValidHTTPToken(name) || !isValidHTTPHeaderValue(normalizedValue))
return Exception { SyntaxError };

Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/xml/XPathFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -568,10 +568,10 @@ Value FunNormalizeSpace::evaluate() const
// https://www.w3.org/TR/1999/REC-xpath-19991116/#function-normalize-space
if (!argumentCount()) {
String s = Value(Expression::evaluationContext().node.get()).toString();
return s.simplifyWhiteSpace(isXMLSpace);
return s.simplifyWhiteSpace(isASCIIWhitespaceWithoutFF<UChar>);
}
String s = argument(0).evaluate().toString();
return s.simplifyWhiteSpace(isXMLSpace);
return s.simplifyWhiteSpace(isASCIIWhitespaceWithoutFF<UChar>);
}

Value FunTranslate::evaluate() const
Expand Down
Loading

0 comments on commit f70bfc7

Please sign in to comment.