Changeset 57990 in webkit


Ignore:
Timestamp:
Apr 21, 2010 9:40:03 AM (14 years ago)
Author:
timothy@apple.com
Message:

Make UserContentURLPattern correctly check for subdomains and the URL
has the same suffix as the pattern. Also improve the parsing of the host.

https://bugs.webkit.org/show_bug.cgi?id=37357

Reviewed by Darin Adler.

  • page/UserContentURLPattern.cpp:

(WebCore::UserContentURLPattern::parse): Simplify the subdomain pattern parsing to
simply check for "*" only or a "*." prefix and then do a substring.
(WebCore::UserContentURLPattern::matchesHost): Check that the host has a "." in the
position before the suffix to ensure it a subdomain and not just a suffix match.

Location:
trunk/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r57987 r57990  
     12010-04-21  Timothy Hatcher  <timothy@apple.com>
     2
     3        Make UserContentURLPattern correctly check for subdomains and the URL
     4        has the same suffix as the pattern. Also improve the parsing of the host.
     5
     6        https://bugs.webkit.org/show_bug.cgi?id=37357
     7
     8        Reviewed by Darin Adler.
     9
     10        * page/UserContentURLPattern.cpp:
     11        (WebCore::UserContentURLPattern::parse): Simplify the subdomain pattern parsing to
     12        simply check for "*" only or a "*." prefix and then do a substring.
     13        (WebCore::UserContentURLPattern::matchesHost): Check that the host has a "." in the
     14        position before the suffix to ensure it a subdomain and not just a suffix match.
     15
    1162010-04-21  Xan Lopez  <xlopez@igalia.com>
    217
  • trunk/WebCore/page/UserContentURLPattern.cpp

    r57923 r57990  
    11/*
    2  * Copyright (C) 2009 Apple Inc. All rights reserved.
     2 * Copyright (C) 2009, 2010 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    8282        if (hostEndPos == -1)
    8383            return false;
    84    
     84
    8585        m_host = pattern.substring(hostStartPos, hostEndPos - hostStartPos);
    86 
    87         // The first component can be '*', which means to match all subdomains.
    88         Vector<String> hostComponents;
    89         m_host.split(".", hostComponents);
    90         if (hostComponents[0] == "*") {
     86        m_matchSubdomains = false;
     87
     88        if (m_host == "*") {
     89            // The pattern can be just '*', which means match all domains.
     90            m_host = "";
    9191            m_matchSubdomains = true;
    92             m_host = "";
    93             for (unsigned i = 1; i < hostComponents.size(); ++i) {
    94                 m_host = m_host + hostComponents[i];
    95                 if (i < hostComponents.size() - 1)
    96                     m_host = m_host + ".";
    97             }
    98         }
    99        
     92        } else if (m_host.startsWith("*.")) {
     93            // The first component can be '*', which means to match all subdomains.
     94            m_host = m_host.substring(2); // Length of "*."
     95            m_matchSubdomains = true;
     96        }
     97
    10098        // No other '*' can occur in the host.
    10199        if (m_host.find("*") != -1)
     
    126124bool UserContentURLPattern::matchesHost(const KURL& test) const
    127125{
    128     if (equalIgnoringCase(test.host(), m_host))
     126    const String& host = test.host();
     127    if (equalIgnoringCase(host, m_host))
    129128        return true;
    130129
     
    137136        return true;
    138137
    139     // Check if the test host is a subdomain of our host.
    140     return test.host().endsWith(m_host, false);
     138    // Check if the domain is a subdomain of our host.
     139    if (!host.endsWith(m_host, false))
     140        return false;
     141
     142    ASSERT(host.length() > m_host.length());
     143
     144    // Check that the character before the suffix is a period.
     145    return host[host.length() - m_host.length() - 1] == '.';
    141146}
    142147
Note: See TracChangeset for help on using the changeset viewer.