Title: [290131] trunk/Source/WebCore
Revision
290131
Author
[email protected]
Date
2022-02-18 09:25:33 -0800 (Fri, 18 Feb 2022)

Log Message

Use more StringView during CSP parsing
https://bugs.webkit.org/show_bug.cgi?id=236784

Reviewed by Darin Adler.

* page/csp/ContentSecurityPolicy.cpp:
(WebCore::ContentSecurityPolicy::reportDirectiveAsSourceExpression const):
* page/csp/ContentSecurityPolicy.h:
* page/csp/ContentSecurityPolicySourceList.cpp:
(WebCore::isCSPDirectiveName):
(WebCore::ContentSecurityPolicySourceList::parse):
(WebCore::ContentSecurityPolicySourceList::parseScheme):
(WebCore::ContentSecurityPolicySourceList::parseHost):
* page/csp/ContentSecurityPolicySourceList.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (290130 => 290131)


--- trunk/Source/WebCore/ChangeLog	2022-02-18 16:47:36 UTC (rev 290130)
+++ trunk/Source/WebCore/ChangeLog	2022-02-18 17:25:33 UTC (rev 290131)
@@ -1,3 +1,20 @@
+2022-02-18  Chris Dumez  <[email protected]>
+
+        Use more StringView during CSP parsing
+        https://bugs.webkit.org/show_bug.cgi?id=236784
+
+        Reviewed by Darin Adler.
+
+        * page/csp/ContentSecurityPolicy.cpp:
+        (WebCore::ContentSecurityPolicy::reportDirectiveAsSourceExpression const):
+        * page/csp/ContentSecurityPolicy.h:
+        * page/csp/ContentSecurityPolicySourceList.cpp:
+        (WebCore::isCSPDirectiveName):
+        (WebCore::ContentSecurityPolicySourceList::parse):
+        (WebCore::ContentSecurityPolicySourceList::parseScheme):
+        (WebCore::ContentSecurityPolicySourceList::parseHost):
+        * page/csp/ContentSecurityPolicySourceList.h:
+
 2022-02-18  Tyler Wilcock  <[email protected]>
 
         AX: AccessibilityScrollView should be resilient to destruction of underlying scroll view

Modified: trunk/Source/WebCore/page/csp/ContentSecurityPolicy.cpp (290130 => 290131)


--- trunk/Source/WebCore/page/csp/ContentSecurityPolicy.cpp	2022-02-18 16:47:36 UTC (rev 290130)
+++ trunk/Source/WebCore/page/csp/ContentSecurityPolicy.cpp	2022-02-18 17:25:33 UTC (rev 290131)
@@ -893,7 +893,7 @@
     logToConsole(message);
 }
 
-void ContentSecurityPolicy::reportDirectiveAsSourceExpression(const String& directiveName, const String& sourceExpression) const
+void ContentSecurityPolicy::reportDirectiveAsSourceExpression(const String& directiveName, StringView sourceExpression) const
 {
     logToConsole("The Content Security Policy directive '" + directiveName + "' contains '" + sourceExpression + "' as a source _expression_. Did you mean '" + directiveName + " ...; " + sourceExpression + "...' (note the semicolon)?");
 }

Modified: trunk/Source/WebCore/page/csp/ContentSecurityPolicy.h (290130 => 290131)


--- trunk/Source/WebCore/page/csp/ContentSecurityPolicy.h	2022-02-18 16:47:36 UTC (rev 290130)
+++ trunk/Source/WebCore/page/csp/ContentSecurityPolicy.h	2022-02-18 17:25:33 UTC (rev 290131)
@@ -145,7 +145,7 @@
     void reportInvalidPluginTypes(const String&) const;
 
     // Used by ContentSecurityPolicySourceList
-    void reportDirectiveAsSourceExpression(const String& directiveName, const String& sourceExpression) const;
+    void reportDirectiveAsSourceExpression(const String& directiveName, StringView sourceExpression) const;
     void reportInvalidPathCharacter(const String& directiveName, const String& value, const char) const;
     void reportInvalidSourceExpression(const String& directiveName, const String& source) const;
     bool urlMatchesSelf(const URL&, bool forFrameSrc) const;

Modified: trunk/Source/WebCore/page/csp/ContentSecurityPolicySourceList.cpp (290130 => 290131)


--- trunk/Source/WebCore/page/csp/ContentSecurityPolicySourceList.cpp	2022-02-18 16:47:36 UTC (rev 290130)
+++ trunk/Source/WebCore/page/csp/ContentSecurityPolicySourceList.cpp	2022-02-18 17:25:33 UTC (rev 290131)
@@ -40,7 +40,7 @@
 
 namespace WebCore {
 
-static bool isCSPDirectiveName(const String& name)
+static bool isCSPDirectiveName(StringView name)
 {
     return equalIgnoringASCIICase(name, ContentSecurityPolicyDirectiveNames::baseURI)
         || equalIgnoringASCIICase(name, ContentSecurityPolicyDirectiveNames::connectSrc)
@@ -205,7 +205,7 @@
                 continue;
             if (isCSPDirectiveName(source->host.value))
                 m_policy.reportDirectiveAsSourceExpression(m_directiveName, source->host.value);
-            m_list.append(ContentSecurityPolicySource(m_policy, source->scheme, source->host.value, source->port.value, source->path, source->host.hasWildcard, source->port.hasWildcard));
+            m_list.append(ContentSecurityPolicySource(m_policy, source->scheme.toString(), source->host.value.toString(), source->port.value, source->path, source->host.hasWildcard, source->port.hasWildcard));
         } else
             m_policy.reportInvalidSourceExpression(m_directiveName, String(beginSource, buffer.position() - beginSource));
 
@@ -305,7 +305,7 @@
             return std::nullopt;
 
         source.host = WTFMove(*host);
-        source.path = WTFMove(*path);
+        source.path = WTFMove(path);
         return source;
     }
 
@@ -317,7 +317,7 @@
             if (!scheme)
                 return std::nullopt;
 
-            source.scheme = WTFMove(*scheme);
+            source.scheme = WTFMove(scheme);
             return source;
         }
 
@@ -333,7 +333,7 @@
             if (buffer.atEnd())
                 return std::nullopt;
 
-            source.scheme = WTFMove(*scheme);
+            source.scheme = WTFMove(scheme);
 
             beginHost = buffer.position();
             skipWhile<isNotColonOrSlash>(buffer);
@@ -373,7 +373,7 @@
         if (!path)
             return std::nullopt;
 
-        source.path = WTFMove(*path);
+        source.path = WTFMove(path);
     }
 
     source.host = WTFMove(*host);
@@ -383,24 +383,24 @@
 //                     ; <scheme> production from RFC 3986
 // scheme      = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
 //
-template<typename CharacterType> std::optional<String> ContentSecurityPolicySourceList::parseScheme(StringParsingBuffer<CharacterType> buffer)
+template<typename CharacterType> StringView ContentSecurityPolicySourceList::parseScheme(StringParsingBuffer<CharacterType> buffer)
 {
     ASSERT(buffer.position() <= buffer.end());
 
     if (buffer.atEnd())
-        return std::nullopt;
+        return { };
 
     auto begin = buffer.position();
 
     if (!skipExactly<isASCIIAlpha>(buffer))
-        return std::nullopt;
+        return { };
 
     skipWhile<isSchemeContinuationCharacter>(buffer);
 
     if (!buffer.atEnd())
-        return std::nullopt;
+        return { };
 
-    return String(begin, buffer.position() - begin);
+    return StringView(begin, buffer.position() - begin);
 }
 
 // host              = [ "*." ] 1*host-char *( "." 1*host-char )
@@ -439,11 +439,11 @@
     }
 
     ASSERT(buffer.atEnd());
-    host.value = String(hostBegin, buffer.position() - hostBegin);
+    host.value = StringView(hostBegin, buffer.position() - hostBegin);
     return host;
 }
 
-template<typename CharacterType> std::optional<String> ContentSecurityPolicySourceList::parsePath(StringParsingBuffer<CharacterType> buffer)
+template<typename CharacterType> String ContentSecurityPolicySourceList::parsePath(StringParsingBuffer<CharacterType> buffer)
 {
     ASSERT(buffer.position() <= buffer.end());
     

Modified: trunk/Source/WebCore/page/csp/ContentSecurityPolicySourceList.h (290130 => 290131)


--- trunk/Source/WebCore/page/csp/ContentSecurityPolicySourceList.h	2022-02-18 16:47:36 UTC (rev 290130)
+++ trunk/Source/WebCore/page/csp/ContentSecurityPolicySourceList.h	2022-02-18 17:25:33 UTC (rev 290131)
@@ -61,7 +61,7 @@
 
 private:
     struct Host {
-        String value;
+        StringView value;
         bool hasWildcard { false };
     };
     struct Port {
@@ -69,7 +69,7 @@
         bool hasWildcard { false };
     };
     struct Source {
-        String scheme;
+        StringView scheme;
         Host host;
         Port port;
         String path;
@@ -79,10 +79,10 @@
 
     template<typename CharacterType> void parse(StringParsingBuffer<CharacterType>);
     template<typename CharacterType> std::optional<Source> parseSource(StringParsingBuffer<CharacterType>);
-    template<typename CharacterType> std::optional<String> parseScheme(StringParsingBuffer<CharacterType>);
+    template<typename CharacterType> StringView parseScheme(StringParsingBuffer<CharacterType>);
     template<typename CharacterType> std::optional<Host> parseHost(StringParsingBuffer<CharacterType>);
     template<typename CharacterType> std::optional<Port> parsePort(StringParsingBuffer<CharacterType>);
-    template<typename CharacterType> std::optional<String> parsePath(StringParsingBuffer<CharacterType>);
+    template<typename CharacterType> String parsePath(StringParsingBuffer<CharacterType>);
     template<typename CharacterType> bool parseNonceSource(StringParsingBuffer<CharacterType>);
     template<typename CharacterType> bool parseHashSource(StringParsingBuffer<CharacterType>);
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to