⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 185683 in webkit


Ignore:
Timestamp:
Jun 17, 2015, 5:51:37 PM (11 years ago)
Author:
achristensen@apple.com
Message:

[Content Extensions] Fail to parse invalid arrays
https://bugs.webkit.org/show_bug.cgi?id=146079
rdar://problem/21422649

Reviewed by Benjamin Poulain.

Source/WebCore:

Covered by new and corrected API tests.

  • contentextensions/ContentExtensionParser.cpp:

(WebCore::ContentExtensions::loadTrigger):
Fail to parse invalid arrays for if-domain, unless-domain, resource-type, and load-type arrays.

Tools:

  • TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp:

(TestWebKitAPI::TEST_F):
Correct and add parsing tests with invalid arrays.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r185682 r185683  
     12015-06-17  Alex Christensen  <achristensen@webkit.org>
     2
     3        [Content Extensions] Fail to parse invalid arrays
     4        https://bugs.webkit.org/show_bug.cgi?id=146079
     5        rdar://problem/21422649
     6
     7        Reviewed by Benjamin Poulain.
     8
     9        Covered by new and corrected API tests.
     10
     11        * contentextensions/ContentExtensionParser.cpp:
     12        (WebCore::ContentExtensions::loadTrigger):
     13        Fail to parse invalid arrays for if-domain, unless-domain, resource-type, and load-type arrays.
     14
    1152015-06-16  Jon Honeycutt  <jhoneycutt@apple.com>
    216
  • trunk/Source/WebCore/contentextensions/ContentExtensionParser.cpp

    r185555 r185683  
    132132
    133133    JSValue resourceTypeValue = triggerObject.get(&exec, Identifier::fromString(&exec, "resource-type"));
    134     if (resourceTypeValue && !exec.hadException()) {
     134    if (!exec.hadException() && resourceTypeValue.isObject()) {
    135135        auto typeFlagsError = getTypeFlags(exec, resourceTypeValue, trigger.flags, readResourceType);
    136136        if (typeFlagsError)
    137137            return typeFlagsError;
    138     }
     138    } else if (!resourceTypeValue.isUndefined())
     139        return ContentExtensionError::JSONInvalidTriggerFlagsArray;
    139140
    140141    JSValue loadTypeValue = triggerObject.get(&exec, Identifier::fromString(&exec, "load-type"));
    141     if (loadTypeValue && !exec.hadException()) {
     142    if (!exec.hadException() && loadTypeValue.isObject()) {
    142143        auto typeFlagsError = getTypeFlags(exec, loadTypeValue, trigger.flags, readLoadType);
    143144        if (typeFlagsError)
    144145            return typeFlagsError;
    145     }
     146    } else if (!loadTypeValue.isUndefined())
     147        return ContentExtensionError::JSONInvalidTriggerFlagsArray;
    146148
    147149    JSValue ifDomain = triggerObject.get(&exec, Identifier::fromString(&exec, "if-domain"));
     
    154156        ASSERT(trigger.domainCondition == Trigger::DomainCondition::None);
    155157        trigger.domainCondition = Trigger::DomainCondition::IfDomain;
    156     }
     158    } else if (!ifDomain.isUndefined())
     159        return ContentExtensionError::JSONInvalidDomainList;
    157160   
    158161    JSValue unlessDomain = triggerObject.get(&exec, Identifier::fromString(&exec, "unless-domain"));
     
    166169            return ContentExtensionError::JSONInvalidDomainList;
    167170        trigger.domainCondition = Trigger::DomainCondition::UnlessDomain;
    168     }
     171    } else if (!unlessDomain.isUndefined())
     172        return ContentExtensionError::JSONInvalidDomainList;
    169173
    170174    return { };
  • trunk/Tools/ChangeLog

    r185674 r185683  
     12015-06-17  Alex Christensen  <achristensen@webkit.org>
     2
     3        [Content Extensions] Fail to parse invalid arrays
     4        https://bugs.webkit.org/show_bug.cgi?id=146079
     5        rdar://problem/21422649
     6
     7        Reviewed by Benjamin Poulain.
     8
     9        * TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp:
     10        (TestWebKitAPI::TEST_F):
     11        Correct and add parsing tests with invalid arrays.
     12
    1132015-06-17  Matt Rajca  <mrajca@apple.com>
    214
  • trunk/Tools/TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp

    r185555 r185683  
    806806    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"load-type\":[5]}}]",
    807807        ContentExtensions::ContentExtensionError::JSONInvalidStringInTriggerFlagsArray);
     808    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"load-type\":5}}]",
     809        ContentExtensions::ContentExtensionError::JSONInvalidTriggerFlagsArray);
     810    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"load-type\":\"first-party\"}}]",
     811        ContentExtensions::ContentExtensionError::JSONInvalidTriggerFlagsArray);
     812    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"load-type\":null}}]",
     813        ContentExtensions::ContentExtensionError::JSONInvalidTriggerFlagsArray);
     814    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"load-type\":false}}]",
     815        ContentExtensions::ContentExtensionError::JSONInvalidTriggerFlagsArray);
    808816    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"resource-type\":{}}}]",
    809817        ContentExtensions::ContentExtensionError::JSONInvalidTriggerFlagsArray);
     
    812820    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"resource-type\":[5]}}]",
    813821        ContentExtensions::ContentExtensionError::JSONInvalidStringInTriggerFlagsArray);
     822    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"resource-type\":5}}]",
     823        ContentExtensions::ContentExtensionError::JSONInvalidTriggerFlagsArray);
     824    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"resource-type\":\"document\"}}]",
     825        ContentExtensions::ContentExtensionError::JSONInvalidTriggerFlagsArray);
     826    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"resource-type\":null}}]",
     827        ContentExtensions::ContentExtensionError::JSONInvalidTriggerFlagsArray);
     828    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"resource-type\":false}}]",
     829        ContentExtensions::ContentExtensionError::JSONInvalidTriggerFlagsArray);
    814830   
    815831    StringBuilder rules;
     
    827843    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"if-domain\":[5]}}]", ContentExtensions::ContentExtensionError::JSONInvalidDomainList);
    828844    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"if-domain\":[\"a\"]}}]", { });
     845    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"if-domain\":\"a\"}}]", ContentExtensions::ContentExtensionError::JSONInvalidDomainList);
     846    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"if-domain\":false}}]", ContentExtensions::ContentExtensionError::JSONInvalidDomainList);
     847    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"if-domain\":null}}]", ContentExtensions::ContentExtensionError::JSONInvalidDomainList);
    829848    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"unless-domain\":{}}}]", ContentExtensions::ContentExtensionError::JSONInvalidDomainList);
    830849    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"unless-domain\":[5]}}]", ContentExtensions::ContentExtensionError::JSONInvalidDomainList);
    831850    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"unless-domain\":[\"\"]}}]", ContentExtensions::ContentExtensionError::JSONInvalidDomainList);
     851    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"unless-domain\":\"a\"}}]", ContentExtensions::ContentExtensionError::JSONInvalidDomainList);
     852    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"unless-domain\":null}}]", ContentExtensions::ContentExtensionError::JSONInvalidDomainList);
     853    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"unless-domain\":false}}]", ContentExtensions::ContentExtensionError::JSONInvalidDomainList);
    832854    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"unless-domain\":[\"A\"]}}]", ContentExtensions::ContentExtensionError::JSONDomainNotLowerCaseASCII);
    833855    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"unless-domain\":[\"\\u00DC\"]}}]", ContentExtensions::ContentExtensionError::JSONDomainNotLowerCaseASCII);
     
    837859    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"if-domain\":[],\"unless-domain\":[\"a\"]}}]", ContentExtensions::ContentExtensionError::JSONInvalidDomainList);
    838860    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"unless-domain\":[]}}]", ContentExtensions::ContentExtensionError::JSONInvalidDomainList);
    839     checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"if-domain\":5}}]", { });
    840     checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"unless-domain\":5}}]", { });
    841     checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"if-domain\":5,\"unless-domain\":5}}]", { });
     861    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"if-domain\":5}}]", ContentExtensions::ContentExtensionError::JSONInvalidDomainList);
     862    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"unless-domain\":5}}]", ContentExtensions::ContentExtensionError::JSONInvalidDomainList);
     863    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"if-domain\":5,\"unless-domain\":5}}]", ContentExtensions::ContentExtensionError::JSONInvalidDomainList);
    842864    checkCompilerError("[{\"action\":{\"type\":\"block\"},\"trigger\":{\"url-filter\":\"webkit.org\",\"if-domain\":[]}}]", ContentExtensions::ContentExtensionError::JSONInvalidDomainList);
    843865   
Note: See TracChangeset for help on using the changeset viewer.