From a93e42ba468b3c9f28f1cb08d6566cf4fdd1bcf8 Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Sun, 23 Aug 2026 16:04:07 +0200 Subject: [PATCH 1/2] Add URL path equality and prefix comparison Cookies needs to compare URL paths, both for equality and for whether one path contains another. Comparing serializations is not right for either: an opaque path can serialize identically to a list of URL path segments, and one path's serialization can be a prefix of another's without covering whole segments. Also let the URL path serializer take a URL path, so that callers holding one no longer have to inline it, and record that a URL path segment never contains U+002F (/), which is what makes the prefix comparison meaningful. Closes #814. Tests: https://github.com/web-platform-tests/wpt/pull/62165 --- url.bs | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 56 insertions(+), 5 deletions(-) diff --git a/url.bs b/url.bs index 3fd9afa1..ecfee5e6 100644 --- a/url.bs +++ b/url.bs @@ -1950,7 +1950,7 @@ the blob URL store between parsing and fetching, while fetching will stil or more URL path segments.

A URL path segment is an ASCII string. It commonly refers to a -directory or a file, but has no predefined meaning. +directory or a file, but has no predefined meaning. It never contains U+002F (/).

A single-dot URL path segment @@ -3220,15 +3220,18 @@ these steps. They return an ASCII string.

The URL path serializer takes a -URL url and then runs these steps. They return an ASCII string. +URL or URL path urlOrPath and then runs these steps. They return +an ASCII string.

    -
  1. If url has an opaque path, then return url's - path. +

  2. Let path be urlOrPath's path if urlOrPath is a + URL; otherwise urlOrPath. + +

  3. If path is a URL path segment, then return path.

  4. Let output be the empty string. -

  5. For each segment of url's path: append +

  6. For each segment of path: append U+002F (/) followed by segment to output.

  7. Return output. @@ -3257,6 +3260,54 @@ run these steps:

+
+

To determine whether a URL path A +equals URL path B, run these steps. +They return a boolean. + +

    +
  1. If A is a URL path segment or B is a + URL path segment, then return whether A is B. + +

  2. If A's size is not B's size, then + return false. + +

  3. For each index of A's indices: if + A[index] is not B[index], then return false. + +

  4. Return true. +

+ +

Comparing URL path segments rather than serializations matters for +URL paths that were not produced by the URL parser: the serialization of an +opaque path can be identical to that of a list of +URL path segments. +

+ +
+

To determine whether a URL path A +starts with URL path B, run +these steps. They return a boolean. + +

    +
  1. If A is a URL path segment or B is a + URL path segment, then return false. + +

  2. If B's size is greater than A's + size, then return false. + +

  3. For each index of B's indices: if + A[index] is not B[index], then return false. + +

  4. Return true. +

+ +

As URL path segments never contain U+002F (/), this can only be true when +B covers whole segments of A. That makes it suitable for deciding whether one +URL path is contained by another, which comparing serializations is not: the +serialization of « "foo" » is a prefix of that of « "foobar" ». +

+

Origin

From 283e6da925fcb44c97badc8730d972b2750574ee Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Mon, 7 Sep 2026 15:12:02 +0200 Subject: [PATCH 2/2] address review feedback --- url.bs | 57 ++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 21 deletions(-) diff --git a/url.bs b/url.bs index ecfee5e6..76109441 100644 --- a/url.bs +++ b/url.bs @@ -1947,10 +1947,17 @@ the blob URL store between parsing and fetching, while fetching will stil

A URL path is either a URL path segment or a list of zero -or more URL path segments. +or more URL path segments. In the latter case the URL path segments never contain +U+002F (/).

A URL path segment is an ASCII string. It commonly refers to a -directory or a file, but has no predefined meaning. It never contains U+002F (/). +directory or a file, but has no predefined meaning. + +

A URL path that is a URL path segment is +opaque and can contain U+002F (/), as with +web+demo:a/b. The URL parser never produces one that starts with U+002F (/), but +URL Pattern does while canonicalizing patterns, so that is not an invariant. +[[URLPATTERN]]

A single-dot URL path segment @@ -3220,19 +3227,19 @@ these steps. They return an ASCII string.

The URL path serializer takes a -URL or URL path urlOrPath and then runs these steps. They return -an ASCII string. +URL or URL path urlOrPath and then runs these steps. They +return an ASCII string.

    -
  1. Let path be urlOrPath's path if urlOrPath is a - URL; otherwise urlOrPath. +

  2. Let path be urlOrPath's path if urlOrPath is + a URL; otherwise urlOrPath.

  3. If path is a URL path segment, then return path.

  4. Let output be the empty string. -

  5. For each segment of path: append - U+002F (/) followed by segment to output. +

  6. For each segment of path: append U+002F (/) followed + by segment to output.

  7. Return output.

@@ -3262,12 +3269,12 @@ run these steps:

To determine whether a URL path A -equals URL path B, run these steps. -They return a boolean. +equals URL path B, run these +steps. They return a boolean.

  1. If A is a URL path segment or B is a - URL path segment, then return whether A is B. + URL path segment, then return whether A is B.

  2. If A's size is not B's size, then return false. @@ -3278,16 +3285,16 @@ They return a boolean.

  3. Return true.

-

Comparing URL path segments rather than serializations matters for -URL paths that were not produced by the URL parser: the serialization of an -opaque path can be identical to that of a list of -URL path segments. +

Comparing URL path segments rather than serializations can matter as +distinct URL paths can serialize identically. E.g., +web+demo:'s path is the empty string, whereas +web+demo://host's path is « », and both serialize to the empty string.

To determine whether a URL path A -starts with URL path B, run -these steps. They return a boolean. +starts with URL path +B, run these steps. They return a boolean.

  1. If A is a URL path segment or B is a @@ -3302,10 +3309,18 @@ these steps. They return a boolean.

  2. Return true.

-

As URL path segments never contain U+002F (/), this can only be true when -B covers whole segments of A. That makes it suitable for deciding whether one -URL path is contained by another, which comparing serializations is not: the -serialization of « "foo" » is a prefix of that of « "foobar" ». +

As URL path segments in a list never contain U+002F (/), +A starts with B only when B covers whole segments of A. +This makes it suitable for deciding whether one URL path is "contained" by another. +Comparing serializations cannot be done naïvely: the serialization +of « "foobar" » starts with the serialization of +« "foo" », but a URL with the latter path does not +contain a URL with the former. + +

Specifications should prefer the origin concept for security +decisions. Treating a URL path as covering the URL paths it contains is a +form of path-based authority that is discordant with the rest of the web platform. It is needed for +legacy features, such as cookies, and is best avoided elsewhere.