Bug 37357 - UserContentURLPattern matches a pattern of "http://ple.com/" for "http://apple.com/"
Summary: UserContentURLPattern matches a pattern of "http://ple.com/" for "http://appl...
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Timothy Hatcher
Depends on:
Reported: 2010-04-09 13:39 PDT by Timothy Hatcher
Modified: 2010-04-21 09:42 PDT (History)
2 users (show)

See Also:

Proposed change (4.57 KB, patch)
2010-04-21 09:25 PDT, Timothy Hatcher
darin: review+
timothy: commit-queue-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Timothy Hatcher 2010-04-09 13:39:49 PDT
The matchesHost function matches domains when it shouldn't.

bool UserContentURLPattern::matchesHost(const KURL& test) const
    if (test.host() == m_host)
        return true;

    if (!m_matchSubdomains)
        return false;

    // If we're matching subdomains, and we have no host, that means the pattern
    // was <scheme>://*/<whatever>, so we match anything.
    if (!m_host.length())
        return true;

    // Check if the test host is a subdomain of our host.
    return test.host().endsWith(m_host, false);

The error is in the last line. Consider test.host() is "apple.com" and m_host from the pattern is "ple.com", this will return true.

We need to look for a period after it checks for the suffix.

Something like:

    const String& host = test.host();

    // Check if the domain is a subdomain of our host.
    if (!host.endsWith(m_host, false))
        return false;

    ASSERT(host.length() > m_host.length());

    // Check that the character before the suffix is a period.
    return host[host.length() - m_host.length() - 1] == '.';
Comment 1 Timothy Hatcher 2010-04-21 09:25:59 PDT
Created attachment 53963 [details]
Proposed change
Comment 2 Darin Adler 2010-04-21 09:28:41 PDT
Comment on attachment 53963 [details]
Proposed change

Is there any way to make tests for UserContentURLPattern? I don't like seeing a bug fix without a test. Can we rig things so this can be tested with DumpRenderTree?

Comment 3 Timothy Hatcher 2010-04-21 09:42:23 PDT
Landed in r57990.

There is no testing harness for UserContentURLPattern yet. I filed bug 37931.