tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 894b391c096fea0839276ebce022d753f6e15856
parent 15b1e288ee499073c52b272213586647ea7e14b8
Author: Randell Jesup <rjesup@mozilla.com>
Date:   Wed,  1 Oct 2025 18:46:00 +0000

Bug 1979087: Use URLPattern for matching Compression Dictionary entries r=edgul,necko-reviewers,kershaw

Differential Revision: https://phabricator.services.mozilla.com/D258606

Diffstat:
Mnetwerk/cache2/Dictionary.cpp | 37++++++++++++++++---------------------
1 file changed, 16 insertions(+), 21 deletions(-)

diff --git a/netwerk/cache2/Dictionary.cpp b/netwerk/cache2/Dictionary.cpp @@ -51,6 +51,8 @@ #include "mozilla/net/NeckoCommon.h" #include "mozilla/net/NeckoParent.h" #include "mozilla/net/NeckoChild.h" +#include "mozilla/net/URLPatternGlue.h" +#include "mozilla/net/urlpattern_glue.h" #include "LoadContextInfo.h" #include "mozilla/ipc/URIUtils.h" @@ -159,31 +161,24 @@ bool DictionaryCacheEntry::Match(const nsACString& aFilePath, mMatchDest.IndexOf( dom::InternalRequest::MapContentPolicyTypeToRequestDestination( aType)) != mMatchDest.NoIndex) { - // XXX remove this when we get URLPattern - // XXX temp: handle https://site/foo* or https://site/foo?query=*, or - // https://site/foo/*, etc - if (mPattern.Last() == '*' && aFilePath.Length() >= mPattern.Length()) { - // XXX not efficient, but this is throw-away code - nsAutoCString partial(aFilePath); - partial.Truncate(mPattern.Length() - 1); - nsAutoCString pattern(mPattern); - pattern.Truncate(mPattern.Length() - 1); - if (partial.Equals(pattern)) { - aLongest = mPattern.Length(); - DICTIONARY_LOG(("Match: %s (longest %u)", - PromiseFlatCString(mURI).get(), aLongest)); - return true; - } + UrlpPattern pattern; + UrlpOptions options; + const nsCString base("https://foo.com/"_ns); + if (!urlp_parse_pattern_from_string(&mPattern, &base, options, + &pattern)) { + DICTIONARY_LOG( + ("Failed to parse dictionary pattern %s", mPattern.get())); return false; - // XXX handle https://site/foo/* ( - } else if (mPattern.Equals(aFilePath)) { - if (mHash.IsEmpty()) { - return false; - } + } + + UrlpInput input = net::CreateUrlpInput(aFilePath); + bool result = net::UrlpPatternTest(pattern, input, Some(base)); + DICTIONARY_LOG(("URLPattern result was %d", result)); + if (result) { aLongest = mPattern.Length(); DICTIONARY_LOG(("Match: %s (longest %u)", mURI.get(), aLongest)); - return true; } + return result; } else { DICTIONARY_LOG((" Failed on matchDest")); }