Commit 0fcec730405 for php

commit 0fcec7304054aab7afb2dfaa89f3516679c84774
Merge: c30231c16af 3e379b435c6
Author: David Carlier <devnexen@gmail.com>
Date:   Sat Nov 21 13:04:00 2026 +0000

    Merge branch 'PHP-8.4' into PHP-8.5

    * PHP-8.4:
      ext/dom: querySelector() rejects a non-ASCII leading identifier.

    # Conflicts:
    #       ext/lexbor/patches/0001-Expose-line-and-column-information-for-use-in-PHP.patch
    #       ext/lexbor/patches/0002-Track-implied-added-nodes-for-options-use-in-PHP.patch
    #       ext/lexbor/patches/0003-Patch-utilities-and-data-structure-to-be-able-to-gen.patch
    #       ext/lexbor/patches/0004-Remove-unused-upper-case-tag-static-data.patch
    #       ext/lexbor/patches/0005-Shrink-size-of-static-binary-search-tree.patch
    #       ext/lexbor/patches/0006-Patch-out-unused-CSS-style-code.patch
    #       ext/lexbor/patches/0009-CSS-Syntax-fixed-non-ASCII-ident-code-point-ranges.patch
    #       ext/lexbor/patches/0010-iCSS-Syntax-fixed-U-FFFD-replacement-boundaries-for-.patch
    #       ext/lexbor/patches/0011-CSS-Syntax-fixed-UTF-8-escapes-in-ident-sequences.patch
    #       ext/lexbor/patches/0011-CSS-fixed-heap-buffer-overflow-in-lexbor-contains-pa.patch
    #       ext/lexbor/patches/0012-CSS-Syntax-fixed-non-ASCII-ident-code-points.patch
    #       ext/lexbor/patches/0012-Encoding-fixed-buffer-overflows-in-malformed-decode-.patch

diff --cc ext/lexbor/patches/0001-Expose-line-and-column-information-for-use-in-PHP.patch
index 9cb75078bd2,9aec14cca5d..8a5a13166a7
--- a/ext/lexbor/patches/0001-Expose-line-and-column-information-for-use-in-PHP.patch
+++ b/ext/lexbor/patches/0001-Expose-line-and-column-information-for-use-in-PHP.patch
@@@ -1,7 -1,7 +1,7 @@@
  From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  From: Niels Dossche <7771979+nielsdos@users.noreply.github.com>
  Date: Sat, 26 Aug 2023 15:08:59 +0200
- Subject: [PATCH 01/22] Expose line and column information for use in PHP
 -Subject: [PATCH 01/12] Expose line and column information for use in PHP
++Subject: [PATCH 01/26] Expose line and column information for use in PHP

  ---
   source/lexbor/dom/interfaces/node.h  |  2 ++
diff --cc ext/lexbor/patches/0002-Track-implied-added-nodes-for-options-use-in-PHP.patch
index 2bf5350d5c4,9f4da029446..c6f567e9954
--- a/ext/lexbor/patches/0002-Track-implied-added-nodes-for-options-use-in-PHP.patch
+++ b/ext/lexbor/patches/0002-Track-implied-added-nodes-for-options-use-in-PHP.patch
@@@ -1,7 -1,7 +1,7 @@@
  From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  From: Niels Dossche <7771979+nielsdos@users.noreply.github.com>
  Date: Mon, 14 Aug 2023 20:18:51 +0200
- Subject: [PATCH 02/22] Track implied added nodes for options use in PHP
 -Subject: [PATCH 02/12] Track implied added nodes for options use in PHP
++Subject: [PATCH 02/26] Track implied added nodes for options use in PHP

  ---
   source/lexbor/html/tree.h                            | 3 +++
diff --cc ext/lexbor/patches/0003-Patch-utilities-and-data-structure-to-be-able-to-gen.patch
index 2f13684510e,fe7068d9bda..e2bddc62b70
--- a/ext/lexbor/patches/0003-Patch-utilities-and-data-structure-to-be-able-to-gen.patch
+++ b/ext/lexbor/patches/0003-Patch-utilities-and-data-structure-to-be-able-to-gen.patch
@@@ -1,7 -1,7 +1,7 @@@
  From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  From: Niels Dossche <7771979+nielsdos@users.noreply.github.com>
  Date: Thu, 24 Aug 2023 22:57:48 +0200
- Subject: [PATCH 03/22] Patch utilities and data structure to be able to
 -Subject: [PATCH 03/12] Patch utilities and data structure to be able to
++Subject: [PATCH 03/26] Patch utilities and data structure to be able to
   generate smaller lookup tables

  Changed the generation script to check if everything fits in 32-bits.
diff --cc ext/lexbor/patches/0004-Remove-unused-upper-case-tag-static-data.patch
index c5f7ef52167,35482388531..2a4dcdc4e4d
--- a/ext/lexbor/patches/0004-Remove-unused-upper-case-tag-static-data.patch
+++ b/ext/lexbor/patches/0004-Remove-unused-upper-case-tag-static-data.patch
@@@ -1,7 -1,7 +1,7 @@@
  From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  From: Niels Dossche <7771979+nielsdos@users.noreply.github.com>
  Date: Wed, 29 Nov 2023 21:26:47 +0100
- Subject: [PATCH 04/22] Remove unused upper case tag static data
 -Subject: [PATCH 04/12] Remove unused upper case tag static data
++Subject: [PATCH 04/26] Remove unused upper case tag static data

  ---
   source/lexbor/tag/res.h | 2 ++
diff --cc ext/lexbor/patches/0005-Shrink-size-of-static-binary-search-tree.patch
index 4d158dbc771,8e9b9524104..5ed745307ad
--- a/ext/lexbor/patches/0005-Shrink-size-of-static-binary-search-tree.patch
+++ b/ext/lexbor/patches/0005-Shrink-size-of-static-binary-search-tree.patch
@@@ -1,7 -1,7 +1,7 @@@
  From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  From: Niels Dossche <7771979+nielsdos@users.noreply.github.com>
  Date: Wed, 29 Nov 2023 21:29:31 +0100
- Subject: [PATCH 05/22] Shrink size of static binary search tree
 -Subject: [PATCH 05/12] Shrink size of static binary search tree
++Subject: [PATCH 05/26] Shrink size of static binary search tree

  This also makes it more efficient on the data cache.
  ---
diff --cc ext/lexbor/patches/0006-Patch-out-unused-CSS-style-code.patch
index b95a36de6f4,0f4e4cd8661..58e64a0441c
--- a/ext/lexbor/patches/0006-Patch-out-unused-CSS-style-code.patch
+++ b/ext/lexbor/patches/0006-Patch-out-unused-CSS-style-code.patch
@@@ -1,7 -1,7 +1,7 @@@
  From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  From: Niels Dossche <7771979+nielsdos@users.noreply.github.com>
  Date: Sun, 7 Jan 2024 21:59:28 +0100
- Subject: [PATCH 06/22] Patch out unused CSS style code
 -Subject: [PATCH 06/12] Patch out unused CSS style code
++Subject: [PATCH 06/26] Patch out unused CSS style code

  ---
   source/lexbor/css/rule.h | 2 ++
diff --cc ext/lexbor/patches/0007-URL-fixed-setters-for-empty-hosts.patch
index 7dc2f925b6d,00000000000..ea8a498ef59
mode 100644,000000..100644
--- a/ext/lexbor/patches/0007-URL-fixed-setters-for-empty-hosts.patch
+++ b/ext/lexbor/patches/0007-URL-fixed-setters-for-empty-hosts.patch
@@@ -1,191 -1,0 +1,191 @@@
 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
 +From: Alexander Borisov <lex.borisov@gmail.com>
 +Date: Fri, 26 Jun 2026 18:55:56 +0300
- Subject: [PATCH 07/22] URL: fixed setters for empty hosts.
++Subject: [PATCH 07/26] URL: fixed setters for empty hosts.
 +MIME-Version: 1.0
 +Content-Type: text/plain; charset=UTF-8
 +Content-Transfer-Encoding: 8bit
 +
 +Empty non-special hosts were represented as empty opaque hosts, so
 +lxb_url_cannot_have_user_pass_port() allowed username, password, and port
 +setters to modify scheme://.
 +
 +For fixed this store empty opaque-host input as LXB_URL_HOST_TYPE_EMPTY.
 +
 +Per report from Máté Kocsis (@kocsismate).
 +
 +This relates to #387 issue on GitHub.
 +---
 + source/lexbor/url/url.c           | 35 ++++++++++++++++++---
 + test/files/lexbor/url/changes.ton | 52 +++++++++++++++++++++++++++++--
 + test/files/lexbor/url/url.ton     |  8 ++++-
 + 3 files changed, 86 insertions(+), 9 deletions(-)
 +
 +diff --git a/source/lexbor/url/url.c b/source/lexbor/url/url.c
 +index 5a11434..86bcf8f 100644
 +--- a/source/lexbor/url/url.c
 ++++ b/source/lexbor/url/url.c
 +@@ -1115,11 +1115,13 @@ lxb_url_host_copy(const lxb_url_host_t *src, lxb_url_host_t *dst,
 +
 +     dst->type = src->type;
 +
 +-    if (src->type <= LXB_URL_HOST_TYPE_OPAQUE) {
 +-        if (src->type == LXB_URL_HOST_TYPE__UNDEF) {
 +-            return LXB_STATUS_OK;
 +-        }
 ++    if (src->type == LXB_URL_HOST_TYPE__UNDEF
 ++        || src->type == LXB_URL_HOST_TYPE_EMPTY)
 ++    {
 ++        return LXB_STATUS_OK;
 ++    }
 +
 ++    if (src->type <= LXB_URL_HOST_TYPE_OPAQUE) {
 +         return lxb_url_str_copy(&src->u.domain,
 +                                 &dst->u.domain, dst_mraw);
 +     }
 +@@ -1152,6 +1154,24 @@ lxb_url_host_set_empty(lxb_url_host_t *host, lexbor_mraw_t *mraw)
 +     host->type = LXB_URL_HOST_TYPE_EMPTY;
 + }
 +
 ++lxb_inline bool
 ++lxb_url_host_is_empty(const lxb_url_host_t *host)
 ++{
 ++    if (host->type == LXB_URL_HOST_TYPE_EMPTY) {
 ++        return true;
 ++    }
 ++
 ++    if (host->type == LXB_URL_HOST_TYPE_DOMAIN) {
 ++        return host->u.domain.length == 0;
 ++    }
 ++
 ++    if (host->type == LXB_URL_HOST_TYPE_OPAQUE) {
 ++        return host->u.opaque.length == 0;
 ++    }
 ++
 ++    return false;
 ++}
 ++
 + static bool
 + lxb_url_host_eq(lxb_url_host_t *host, const lxb_char_t *data, size_t length)
 + {
 +@@ -1251,7 +1271,7 @@ lxb_url_normalized_windows_drive_letter(const lxb_char_t *data,
 + static bool
 + lxb_url_cannot_have_user_pass_port(lxb_url_t *url)
 + {
 +-    return url->host.type == LXB_URL_HOST_TYPE_EMPTY
 ++    return lxb_url_host_is_empty(&url->host)
 +     || url->host.type == LXB_URL_HOST_TYPE__UNDEF
 +     || url->scheme.type == LXB_URL_SCHEMEL_TYPE_FILE;
 + }
 +@@ -3978,6 +3998,11 @@ lxb_url_opaque_host_parse(lxb_url_parser_t *parser, const lxb_char_t *data,
 +     lxb_status_t status;
 +     const lxb_char_t *p;
 +
 ++    if (data == end) {
 ++        lxb_url_host_set_empty(host, mraw);
 ++        return LXB_STATUS_OK;
 ++    }
 ++
 +     p = data;
 +
 +     while (p < end) {
 +diff --git a/test/files/lexbor/url/changes.ton b/test/files/lexbor/url/changes.ton
 +index 07bc944..1a0b6e3 100644
 +--- a/test/files/lexbor/url/changes.ton
 ++++ b/test/files/lexbor/url/changes.ton
 +@@ -1,5 +1,5 @@
 + [
 +-    /* Test count: 1 */
 ++    /* Test count: 47 */
 +     /* 1 */
 +     {
 +         "url": "https://user:pass@lexbor.com/docs/html/path?x=y&a=b#best-fragment",
 +@@ -982,9 +982,53 @@
 +         "failed": false
 +     },
 +     /* 45 */
 ++    {
 ++        "url": "scheme://",
 ++        "done": "scheme://",
 ++        "change": {
 ++            "href": null,
 ++            "protocol": null,
 ++            "username": "user",
 ++            "password": "pass",
 ++            "host": null,
 ++            "hostname": null,
 ++            "port": "433",
 ++            "pathname": null,
 ++            "search": null,
 ++            "hash": null
 ++        },
 ++        "scheme": "scheme",
 ++        "host": "",
 ++        "path": "",
 ++        "failed": false
 ++    },
 ++    /* 46 */
 ++    {
 ++        "url": "scheme://host",
 ++        "done": "scheme://host:433",
 ++        "change": {
 ++            "href": null,
 ++            "protocol": null,
 ++            "username": null,
 ++            "password": null,
 ++            "host": null,
 ++            "hostname": null,
 ++            "port": "433",
 ++            "pathname": null,
 ++            "search": null,
 ++            "hash": null
 ++        },
 ++        "scheme": "scheme",
 ++        "host": "host",
 ++        "port": 433,
 ++        "has_port": true,
 ++        "path": "",
 ++        "failed": false
 ++    },
 ++    /* 47 */
 +     {
 +         "url": "https://example.com:432",
 +-        "done": "https://example.com:432",
 ++        "done": "https://example.com:432/",
 +         "change": {
 +             "href": null,
 +             "protocol": null,
 +@@ -999,7 +1043,9 @@
 +         },
 +         "scheme": "https",
 +         "host": "example.com",
 +-        "port": "432",
 ++        "port": 432,
 ++        "has_port": true,
 ++        "path": "/",
 +         "failed": true
 +     }
 + ]
 +diff --git a/test/files/lexbor/url/url.ton b/test/files/lexbor/url/url.ton
 +index 2baa4bc..85794c5 100644
 +--- a/test/files/lexbor/url/url.ton
 ++++ b/test/files/lexbor/url/url.ton
 +@@ -1,5 +1,5 @@
 + [
 +-    /* Test count: 7 */
 ++    /* Test count: 8 */
 +     /* 1 */
 +     {
 +         "url": "https://user:pass@lexbor.com:450/docs/lexbor/?search=lxb_status_t#version",
 +@@ -74,5 +74,11 @@
 +         "path": "",
 +         "failed": false,
 +         "encoding": "utf-8"
 ++    },
 ++    /* 8 */
 ++    {
 ++        "url": "scheme://:433",
 ++        "failed": true,
 ++        "encoding": "utf-8"
 +     }
 + ]
diff --cc ext/lexbor/patches/0008-URL-fixed-uninitialized-memory-in-the-path-buffer-gr.patch
index fc24314c743,00000000000..745e49983da
mode 100644,000000..100644
--- a/ext/lexbor/patches/0008-URL-fixed-uninitialized-memory-in-the-path-buffer-gr.patch
+++ b/ext/lexbor/patches/0008-URL-fixed-uninitialized-memory-in-the-path-buffer-gr.patch
@@@ -1,37 -1,0 +1,37 @@@
 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
 +From: Alexander Borisov <lex.borisov@gmail.com>
 +Date: Fri, 5 Jun 2026 22:13:32 +0300
- Subject: [PATCH 08/22] URL: fixed uninitialized memory in the path buffer
++Subject: [PATCH 08/26] URL: fixed uninitialized memory in the path buffer
 + growth.
 +
 +When a path was long enough to outgrow the on-stack buffer, the first
 +move to the heap didn't copy what was already written, so the start of
 +the path could contain garbage. Also fixed the 'last' pointer after the
 +move.
 +
 +Per report from Recep Asan (recep@asan.me)
 +---
 + source/lexbor/url/url.c | 3 ++-
 + 1 file changed, 2 insertions(+), 1 deletion(-)
 +
 +diff --git a/source/lexbor/url/url.c b/source/lexbor/url/url.c
 +index 86bcf8f..b6c0a1e 100644
 +--- a/source/lexbor/url/url.c
 ++++ b/source/lexbor/url/url.c
 +@@ -499,6 +499,7 @@ lxb_url_scheme_length = sizeof(lxb_url_scheme_res) / sizeof(lxb_url_scheme_data_
 +             if (tmp == NULL) {                                                \
 +                 return NULL;                                                  \
 +             }                                                                 \
 ++            memcpy(tmp, (sbuf_begin), offset);                                \
 +         }                                                                     \
 +         else {                                                                \
 +             tmp = lexbor_realloc((sbuf_begin), new_len);                      \
 +@@ -509,7 +510,7 @@ lxb_url_scheme_length = sizeof(lxb_url_scheme_res) / sizeof(lxb_url_scheme_data_
 +         }                                                                     \
 +                                                                               \
 +         (sbuf) = tmp + offset;                                                \
 +-        (last) = sbuf + lst;                                                  \
 ++        (last) = tmp + lst;                                                   \
 +         (sbuf_begin) = tmp;                                                   \
 +         (sbuf_end) = tmp + new_len;                                           \
 +     }                                                                         \
diff --cc ext/lexbor/patches/0009-Fix-parsing-for-URL-containing-empty-host-and-userin.patch
index d45d0b75886,00000000000..3a9b367139e
mode 100644,000000..100644
--- a/ext/lexbor/patches/0009-Fix-parsing-for-URL-containing-empty-host-and-userin.patch
+++ b/ext/lexbor/patches/0009-Fix-parsing-for-URL-containing-empty-host-and-userin.patch
@@@ -1,48 -1,0 +1,48 @@@
 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
 +From: =?UTF-8?q?M=C3=A1t=C3=A9=20Kocsis?= <kocsismate@woohoolabs.com>
 +Date: Thu, 9 Jul 2026 21:51:05 +0200
- Subject: [PATCH 09/22] Fix parsing for URL containing empty host and userinfo
++Subject: [PATCH 09/26] Fix parsing for URL containing empty host and userinfo
 +
 +The returned error code (LXB_URL_ERROR_TYPE_INVALID_CREDENTIALS) apparently contradicts the specification:
 +
 +"If atSignSeen is true and buffer is the empty string, host-missing validation error, return failure."
 +---
 + source/lexbor/url/url.c                     | 2 +-
 + test/files/lexbor/url/username_password.ton | 8 +++++++-
 + 2 files changed, 8 insertions(+), 2 deletions(-)
 +
 +diff --git a/source/lexbor/url/url.c b/source/lexbor/url/url.c
 +index b6c0a1e..19ec238 100644
 +--- a/source/lexbor/url/url.c
 ++++ b/source/lexbor/url/url.c
 +@@ -1814,7 +1814,7 @@ again:
 +         if (at_sign) {
 +             if (begin == p || begin == p - 1) {
 +                 status = lxb_url_log_append(parser, p,
 +-                                            LXB_URL_ERROR_TYPE_INVALID_CREDENTIALS);
 ++                                            LXB_URL_ERROR_TYPE_HOST_MISSING);
 +                 if (status != LXB_STATUS_OK) {
 +                     lxb_url_parse_return(orig_data, buf, status);
 +                 }
 +diff --git a/test/files/lexbor/url/username_password.ton b/test/files/lexbor/url/username_password.ton
 +index 28a27fd..5a5e63e 100644
 +--- a/test/files/lexbor/url/username_password.ton
 ++++ b/test/files/lexbor/url/username_password.ton
 +@@ -1,5 +1,5 @@
 + [
 +-    /* Test count: 11 */
 ++    /* Test count: 12 */
 +     /* 1 */
 +     {
 +         "url": "https://user:password@lexbor.com",
 +@@ -124,4 +124,10 @@
 +         "failed": false,
 +         "encoding": "utf-8"
 +     }
 ++    /* 12 */
 ++    {
 ++        "url": "https://user:pass@",
 ++        "failed": true,
 ++        "encoding": "utf-8"
 ++    }
 + ]
diff --cc ext/lexbor/patches/0010-Percent-encode-the-caret-in-the-path.patch
index 7ff8d6f9582,00000000000..bfd69c9a3f9
mode 100644,000000..100644
--- a/ext/lexbor/patches/0010-Percent-encode-the-caret-in-the-path.patch
+++ b/ext/lexbor/patches/0010-Percent-encode-the-caret-in-the-path.patch
@@@ -1,29 -1,0 +1,29 @@@
 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
 +From: =?UTF-8?q?M=C3=A1t=C3=A9=20Kocsis?= <kocsismate@woohoolabs.com>
 +Date: Fri, 10 Jul 2026 22:31:16 +0200
- Subject: [PATCH 10/22] Percent-encode the caret in the path
++Subject: [PATCH 10/26] Percent-encode the caret in the path
 +
 +The caret (^) is part of the path percent-encode set:
 +
 +"The path percent-encode set is a percent-encode set consisting of the query percent-encode set and U+003F (?), U+005E (^), U+0060 (`), U+007B ({), and U+007D (})."
 +
 +Until now, this character wasn't percent-encoded in the path likely due to a copy-paste error. This is mistake is fixed by adding LXB_URL_MAP_PATH to the lxb_url_map entry for the caret.
 +
 +Originally reported at https://github.com/php/php-src/issues/22628
 +---
 + source/lexbor/url/url.c | 2 +-
 + 1 file changed, 1 insertion(+), 1 deletion(-)
 +
 +diff --git a/source/lexbor/url/url.c b/source/lexbor/url/url.c
 +index 19ec238..de19239 100644
 +--- a/source/lexbor/url/url.c
 ++++ b/source/lexbor/url/url.c
 +@@ -159,7 +159,7 @@ static const uint8_t lxb_url_map[256] =
 +     LXB_URL_MAP_USERINFO|LXB_URL_MAP_COMPONENT|LXB_URL_MAP_X_WWW_FORM, /* 0x5b ([) */
 +     LXB_URL_MAP_USERINFO|LXB_URL_MAP_COMPONENT|LXB_URL_MAP_X_WWW_FORM, /* 0x5c (\) */
 +     LXB_URL_MAP_USERINFO|LXB_URL_MAP_COMPONENT|LXB_URL_MAP_X_WWW_FORM, /* 0x5d (]) */
 +-    LXB_URL_MAP_USERINFO|LXB_URL_MAP_COMPONENT|LXB_URL_MAP_X_WWW_FORM, /* 0x5e (^) */
 ++    LXB_URL_MAP_USERINFO|LXB_URL_MAP_PATH|LXB_URL_MAP_COMPONENT|LXB_URL_MAP_X_WWW_FORM, /* 0x5e (^) */
 +     LXB_URL_MAP_UNDEF, /* 0x5f (_) */
 +     LXB_URL_MAP_PATH|LXB_URL_MAP_FRAGMENT|LXB_URL_MAP_USERINFO|LXB_URL_MAP_COMPONENT|LXB_URL_MAP_X_WWW_FORM, /* 0x60 (`) */
 +     LXB_URL_MAP_UNDEF, /* 0x61 (a) */
diff --cc ext/lexbor/patches/0011-CSS-fixed-heap-buffer-overflow-in-lexbor-contains-pa.patch
index 975f400b98f,3d0bb9ecdc0..8d32202c968
--- a/ext/lexbor/patches/0011-CSS-fixed-heap-buffer-overflow-in-lexbor-contains-pa.patch
+++ b/ext/lexbor/patches/0011-CSS-fixed-heap-buffer-overflow-in-lexbor-contains-pa.patch
@@@ -1,7 -1,7 +1,7 @@@
  From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  From: Alexander Borisov <lex.borisov@gmail.com>
  Date: Fri, 5 Jun 2026 22:34:23 +0300
- Subject: [PATCH 11/22] CSS: fixed heap buffer overflow in :lexbor-contains()
 -Subject: [PATCH 07/12] CSS: fixed heap buffer overflow in :lexbor-contains()
++Subject: [PATCH 11/26] CSS: fixed heap buffer overflow in :lexbor-contains()
   parsing.

  The contains string buffer was allocated by the size of the string
diff --cc ext/lexbor/patches/0012-Encoding-fixed-buffer-overflows-in-malformed-decode-.patch
index bc243bc250e,cec351fb639..b7c87caf18f
--- a/ext/lexbor/patches/0012-Encoding-fixed-buffer-overflows-in-malformed-decode-.patch
+++ b/ext/lexbor/patches/0012-Encoding-fixed-buffer-overflows-in-malformed-decode-.patch
@@@ -1,7 -1,7 +1,7 @@@
  From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  From: Alexander Borisov <lex.borisov@gmail.com>
  Date: Wed, 10 Jun 2026 19:50:10 +0300
- Subject: [PATCH 12/22] Encoding: fixed buffer overflows in malformed decode
 -Subject: [PATCH 08/12] Encoding: fixed buffer overflows in malformed decode
++Subject: [PATCH 12/26] Encoding: fixed buffer overflows in malformed decode
   replay.

  Fixed out-of-bounds writes in buffering decoders when replacement output
diff --cc ext/lexbor/patches/0013-URL-fixed-tail-pointer-in-URLSearchParams-for-delimi.patch
index 38a36be323e,00000000000..de4d33a4ea6
mode 100644,000000..100644
--- a/ext/lexbor/patches/0013-URL-fixed-tail-pointer-in-URLSearchParams-for-delimi.patch
+++ b/ext/lexbor/patches/0013-URL-fixed-tail-pointer-in-URLSearchParams-for-delimi.patch
@@@ -1,29 -1,0 +1,29 @@@
 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
 +From: Alexander Borisov <lex.borisov@gmail.com>
 +Date: Fri, 5 Jun 2026 21:46:26 +0300
- Subject: [PATCH 13/22] URL: fixed tail pointer in URLSearchParams for
++Subject: [PATCH 13/26] URL: fixed tail pointer in URLSearchParams for
 + delimiter-free query.
 +
 +When a query had a single token without '=' or '&' (e.g. "?abc"), the
 +internal tail pointer wasn't updated, so a later append() could lose the
 +added parameter (and write through a stale pointer). Fixed by keeping the
 +tail pointer in sync.
 +
 +Per report from Xiansheng Cao (@HMF2021)
 +---
 + source/lexbor/url/url.c | 2 ++
 + 1 file changed, 2 insertions(+)
 +
 +diff --git a/source/lexbor/url/url.c b/source/lexbor/url/url.c
 +index de19239..fcae2d6 100644
 +--- a/source/lexbor/url/url.c
 ++++ b/source/lexbor/url/url.c
 +@@ -5106,6 +5106,8 @@ lxb_url_search_params_parse(lxb_url_search_params_t *search_params,
 +             return status;
 +         }
 +
 ++        last = entry;
 ++
 +         lexbor_str_init(&entry->value, mraw, 0);
 +         if (entry->value.data == NULL) {
 +             return LXB_STATUS_ERROR_MEMORY_ALLOCATION;
diff --cc ext/lexbor/patches/0014-URL-Fix-parsing-of-usernames-containing.patch
index 9e1cc2fd442,00000000000..aa557cb10f1
mode 100644,000000..100644
--- a/ext/lexbor/patches/0014-URL-Fix-parsing-of-usernames-containing.patch
+++ b/ext/lexbor/patches/0014-URL-Fix-parsing-of-usernames-containing.patch
@@@ -1,38 -1,0 +1,38 @@@
 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
 +From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= <tim@bastelstu.be>
 +Date: Fri, 31 Jul 2026 20:56:18 +0200
- Subject: [PATCH 14/22] URL: Fix parsing of usernames containing `@`
++Subject: [PATCH 14/26] URL: Fix parsing of usernames containing `@`
 +
 +Fixes lexbor/lexbor#399.
 +---
 + source/lexbor/url/url.c | 17 +++++++----------
 + 1 file changed, 7 insertions(+), 10 deletions(-)
 +
 +diff --git a/source/lexbor/url/url.c b/source/lexbor/url/url.c
 +index fcae2d6..654e2e6 100644
 +--- a/source/lexbor/url/url.c
 ++++ b/source/lexbor/url/url.c
 +@@ -1753,16 +1753,13 @@ again:
 +                         break;
 +                     }
 +
 +-                    if (pswd == NULL || !at_sign) {
 +-                        tmp = (pswd != NULL) ? pswd - 1 : p;
 +-
 +-                        if (tmp > begin) {
 +-                            status = lxb_url_percent_encode_after_utf_8(begin, tmp,
 +-                                                        &url->username, url->mraw,
 +-                                                        LXB_URL_MAP_USERINFO, false);
 +-                            if (status != LXB_STATUS_OK) {
 +-                                lxb_url_parse_return(orig_data, buf, status);
 +-                            }
 ++                    tmp = (pswd != NULL) ? pswd - 1 : p;
 ++                    if (tmp > begin) {
 ++                        status = lxb_url_percent_encode_after_utf_8(begin, tmp,
 ++                                                    &url->username, url->mraw,
 ++                                                    LXB_URL_MAP_USERINFO, false);
 ++                        if (status != LXB_STATUS_OK) {
 ++                            lxb_url_parse_return(orig_data, buf, status);
 +                         }
 +                     }
 +
diff --cc ext/lexbor/patches/0015-Unicode-fixed-uninitialized-memory-in-IDNA-buffer-gr.patch
index a50bd4d5a25,00000000000..313d0cda436
mode 100644,000000..100644
--- a/ext/lexbor/patches/0015-Unicode-fixed-uninitialized-memory-in-IDNA-buffer-gr.patch
+++ b/ext/lexbor/patches/0015-Unicode-fixed-uninitialized-memory-in-IDNA-buffer-gr.patch
@@@ -1,81 -1,0 +1,81 @@@
 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
 +From: Alexander Borisov <lex.borisov@gmail.com>
 +Date: Mon, 7 Sep 2026 22:11:39 +0300
- Subject: [PATCH 15/22] Unicode: fixed uninitialized memory in IDNA buffer
++Subject: [PATCH 15/26] Unicode: fixed uninitialized memory in IDNA buffer
 + growth.
 +
 +When an IDNA buffer outgrew the stack allocation, the move to the heap
 +did not copy the existing contents. The converted domain could therefore
 +contain uninitialized heap data.
 +
 +Fixed copying of the codepoint, ASCII and UTF-8 buffers.
 +
 +Per report from Muhammad Daffa (@daffainfo).
 +---
 + source/lexbor/unicode/idna.c | 28 +++++++++++++++++++---------
 + 1 file changed, 19 insertions(+), 9 deletions(-)
 +
 +diff --git a/source/lexbor/unicode/idna.c b/source/lexbor/unicode/idna.c
 +index 754f6b2..b31ae33 100644
 +--- a/source/lexbor/unicode/idna.c
 ++++ b/source/lexbor/unicode/idna.c
 +@@ -117,12 +117,14 @@ lxb_unicode_idna_realloc(lxb_codepoint_t *buf, const lxb_codepoint_t *buffer,
 +     lxb_codepoint_t *tmp;
 +
 +     nlen = ((*buf_end - buf) * 4) + len;
 +-
 ++
 +     if (buf == buffer) {
 +         tmp = lexbor_malloc(nlen * sizeof(lxb_codepoint_t));
 +         if (tmp == NULL) {
 +             return NULL;
 +         }
 ++
 ++        memcpy(tmp, buf, (*buf_p - buf) * sizeof(lxb_codepoint_t));
 +     }
 +     else {
 +         tmp = lexbor_realloc(buf, nlen * sizeof(lxb_codepoint_t));
 +@@ -458,13 +460,17 @@ lxb_unicode_idna_ascii_puny_cb(const lxb_char_t *data, size_t length, void *ctx,
 +
 +         if (asc->buf == asc->buffer) {
 +             tmp = lexbor_malloc(nlen);
 ++            if (tmp == NULL) {
 ++                return LXB_STATUS_ERROR_MEMORY_ALLOCATION;
 ++            }
 ++
 ++            memcpy(tmp, asc->buf, asc->p - asc->buf);
 +         }
 +         else {
 +             tmp = lexbor_realloc(asc->buf, nlen);
 +-        }
 +-
 +-        if (tmp == NULL) {
 +-            return LXB_STATUS_ERROR_MEMORY_ALLOCATION;
 ++            if (tmp == NULL) {
 ++                return LXB_STATUS_ERROR_MEMORY_ALLOCATION;
 ++            }
 +         }
 +
 +         asc->p = tmp + (asc->p - asc->buf);
 +@@ -711,13 +717,17 @@ lxb_unicode_idna_to_unicode_cb(const lxb_codepoint_t *part, size_t len,
 +
 +         if (asc->buf == asc->buffer) {
 +             tmp = lexbor_malloc(nlen);
 ++            if (tmp == NULL) {
 ++                return LXB_STATUS_ERROR_MEMORY_ALLOCATION;
 ++            }
 ++
 ++            memcpy(tmp, asc->buf, asc->p - asc->buf);
 +         }
 +         else {
 +             tmp = lexbor_realloc(asc->buf, nlen);
 +-        }
 +-
 +-        if (tmp == NULL) {
 +-            return LXB_STATUS_ERROR_MEMORY_ALLOCATION;
 ++            if (tmp == NULL) {
 ++                return LXB_STATUS_ERROR_MEMORY_ALLOCATION;
 ++            }
 +         }
 +
 +         asc->p = tmp + (asc->p - asc->buf);
diff --cc ext/lexbor/patches/0016-URL-encode-opaque-path-spaces-before-query-and-fragm.patch
index bcf14d13987,00000000000..e6bc91549d4
mode 100644,000000..100644
--- a/ext/lexbor/patches/0016-URL-encode-opaque-path-spaces-before-query-and-fragm.patch
+++ b/ext/lexbor/patches/0016-URL-encode-opaque-path-spaces-before-query-and-fragm.patch
@@@ -1,38 -1,0 +1,38 @@@
 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
 +From: =?UTF-8?q?M=C3=A1t=C3=A9=20Kocsis?= <kocsismate@woohoolabs.com>
 +Date: Fri, 11 Sep 2026 21:58:45 +0200
- Subject: [PATCH 16/22] URL: encode opaque path spaces before query and
++Subject: [PATCH 16/26] URL: encode opaque path spaces before query and
 + fragment. (#405)
 +MIME-Version: 1.0
 +Content-Type: text/plain; charset=UTF-8
 +Content-Transfer-Encoding: 8bit
 +
 +Percent-encode only the space immediately preceding a query or fragment delimiter, while preserving validation errors for every parsed space.
 +
 +This way, Lexbor will correctly follow "If remaining starts with U+003F (?) or U+0023 (#), then append "%20" to url’s path." in the "opaque path state".
 +---
 + source/lexbor/url/url.c | 11 +++++++++++
 + 1 file changed, 11 insertions(+)
 +
 +diff --git a/source/lexbor/url/url.c b/source/lexbor/url/url.c
 +index 654e2e6..98ee304 100644
 +--- a/source/lexbor/url/url.c
 ++++ b/source/lexbor/url/url.c
 +@@ -2340,6 +2340,17 @@ again:
 +                     lxb_url_parse_return(orig_data, buf, status);
 +                 }
 +
 ++                /* Encode only the space immediately before a query or fragment. */
 ++                if (p > begin && p[-1] == ' ') {
 ++                    tmp_str.length--;
 ++                    if (lexbor_str_append(&tmp_str, url->mraw,
 ++                                          (const lxb_char_t *) "%20", 3) == NULL)
 ++                    {
 ++                        lxb_url_parse_return(orig_data, buf,
 ++                                             LXB_STATUS_ERROR_MEMORY_ALLOCATION);
 ++                    }
 ++                }
 ++
 +                 status = lxb_url_path_list_push(url, &tmp_str);
 +                 if (status != LXB_STATUS_OK) {
 +                     lxb_url_parse_return(orig_data, buf, status);
diff --cc ext/lexbor/patches/0017-URL-Fix-lxb_url_serialize_fragment-without-a-query-4.patch
index b645c0024a8,00000000000..1fa964f2120
mode 100644,000000..100644
--- a/ext/lexbor/patches/0017-URL-Fix-lxb_url_serialize_fragment-without-a-query-4.patch
+++ b/ext/lexbor/patches/0017-URL-Fix-lxb_url_serialize_fragment-without-a-query-4.patch
@@@ -1,25 -1,0 +1,25 @@@
 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
 +From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= <tim@tideways-gmbh.com>
 +Date: Fri, 11 Sep 2026 22:45:33 +0200
- Subject: [PATCH 17/22] URL: Fix `lxb_url_serialize_fragment()` without a query
++Subject: [PATCH 17/26] URL: Fix `lxb_url_serialize_fragment()` without a query
 + (#410)
 +
 +The `lxb_url_serialize_fragment()` function checked if the query contained data
 +before correctly serializing the fragment. Check for the fragment instead.
 +---
 + source/lexbor/url/url.c | 2 +-
 + 1 file changed, 1 insertion(+), 1 deletion(-)
 +
 +diff --git a/source/lexbor/url/url.c b/source/lexbor/url/url.c
 +index 98ee304..faf553b 100644
 +--- a/source/lexbor/url/url.c
 ++++ b/source/lexbor/url/url.c
 +@@ -4915,7 +4915,7 @@ lxb_status_t
 + lxb_url_serialize_fragment(const lxb_url_t *url,
 +                            lexbor_serialize_cb_f cb, void *ctx)
 + {
 +-    if (url->query.data != NULL) {
 ++    if (url->fragment.data != NULL) {
 +         return cb(url->fragment.data, url->fragment.length, ctx);
 +     }
 +
diff --cc ext/lexbor/patches/0018-URL-expose-component-reset-functions.-415.patch
index ed27f5fe6c7,00000000000..1a972b600bc
mode 100644,000000..100644
--- a/ext/lexbor/patches/0018-URL-expose-component-reset-functions.-415.patch
+++ b/ext/lexbor/patches/0018-URL-expose-component-reset-functions.-415.patch
@@@ -1,110 -1,0 +1,110 @@@
 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
 +From: =?UTF-8?q?M=C3=A1t=C3=A9=20Kocsis?= <kocsismate@woohoolabs.com>
 +Date: Tue, 22 Sep 2026 22:20:28 +0200
- Subject: [PATCH 18/22] URL: expose component reset functions. (#415)
++Subject: [PATCH 18/26] URL: expose component reset functions. (#415)
 +
 +* URL: expose component reset functions.
 +
 +Make the path, host and fragment reset functions public and add lxb_url_query_set_null().
 +
 +* Add documentation for the newly exposed functions
 +---
 + source/lexbor/url/url.c | 14 ++++++++++---
 + source/lexbor/url/url.h | 45 +++++++++++++++++++++++++++++++++++++++++
 + 2 files changed, 56 insertions(+), 3 deletions(-)
 +
 +diff --git a/source/lexbor/url/url.c b/source/lexbor/url/url.c
 +index faf553b..9bfc2aa 100644
 +--- a/source/lexbor/url/url.c
 ++++ b/source/lexbor/url/url.c
 +@@ -923,7 +923,7 @@ lxb_url_scheme_copy_special(const lxb_url_scheme_data_t *src,
 +     return lxb_url_str_copy(&src->name, &dst->name, dst_mraw);
 + }
 +
 +-static void
 ++void
 + lxb_url_path_set_null(lxb_url_t *url)
 + {
 +     if (url->path.str.data == NULL) {
 +@@ -1147,7 +1147,7 @@ lxb_url_host_destroy(lxb_url_host_t *host, lexbor_mraw_t *mraw)
 +     }
 + }
 +
 +-static void
 ++void
 + lxb_url_host_set_empty(lxb_url_host_t *host, lexbor_mraw_t *mraw)
 + {
 +     lxb_url_host_destroy(host, mraw);
 +@@ -1197,7 +1197,15 @@ lxb_url_port_set(lxb_url_t *url, uint16_t port)
 +     url->has_port = true;
 + }
 +
 +-static void
 ++void
 ++lxb_url_query_set_null(lxb_url_t *url)
 ++{
 ++    if (url->query.data != NULL) {
 ++        (void) lexbor_str_destroy(&url->query, url->mraw, false);
 ++    }
 ++}
 ++
 ++void
 + lxb_url_fragment_set_null(lxb_url_t *url)
 + {
 +     if (url->fragment.data != NULL) {
 +diff --git a/source/lexbor/url/url.h b/source/lexbor/url/url.h
 +index 4ed3f32..b9e4973 100644
 +--- a/source/lexbor/url/url.h
 ++++ b/source/lexbor/url/url.h
 +@@ -763,6 +763,51 @@ LXB_API lxb_status_t
 + lxb_url_search_params_serialize(lxb_url_search_params_t *search_params,
 +                                 lexbor_callback_f cb, void *ctx);
 +
 ++/*
 ++ * Reset the URL path to an empty list.
 ++ *
 ++ * Frees the path buffer using url->mraw, resets the segment count and clears
 ++ * the opaque flag. Does nothing if the path buffer is already NULL.
 ++ *
 ++ * @param[in, out] URL object. Not NULL.
 ++ */
 ++LXB_API void
 ++lxb_url_path_set_null(lxb_url_t *url);
 ++
 ++/*
 ++ * Set the host to the empty host.
 ++ *
 ++ * Frees any domain or opaque host buffer using mraw and sets the host type
 ++ * to LXB_URL_HOST_TYPE_EMPTY.
 ++ *
 ++ * @param[in, out] Host object. Not NULL.
 ++ * @param[in] Memory object associated with the host. Not NULL.
 ++ */
 ++LXB_API void
 ++lxb_url_host_set_empty(lxb_url_host_t *host, lexbor_mraw_t *mraw);
 ++
 ++/*
 ++ * Set the URL query to null.
 ++ *
 ++ * Frees the query buffer using url->mraw. Does nothing if the query
 ++ * is already null.
 ++ *
 ++ * @param[in, out] URL object. Not NULL.
 ++ */
 ++LXB_API void
 ++lxb_url_query_set_null(lxb_url_t *url);
 ++
 ++/*
 ++ * Set the URL fragment to null.
 ++ *
 ++ * Frees the fragment buffer using url->mraw. Does nothing if the
 ++ * fragment is already null.
 ++ *
 ++ * @param[in, out] URL object. Not NULL.
 ++ */
 ++LXB_API void
 ++lxb_url_fragment_set_null(lxb_url_t *url);
 ++
 + /*
 +  * Inline functions.
 +  */
diff --cc ext/lexbor/patches/0019-URL-Fix-parsing-of-query-and-fragment-after-a-dot-co.patch
index c1cd41a6b75,00000000000..9f16a867ec8
mode 100644,000000..100644
--- a/ext/lexbor/patches/0019-URL-Fix-parsing-of-query-and-fragment-after-a-dot-co.patch
+++ b/ext/lexbor/patches/0019-URL-Fix-parsing-of-query-and-fragment-after-a-dot-co.patch
@@@ -1,416 -1,0 +1,416 @@@
 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
 +From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= <tim@tideways-gmbh.com>
 +Date: Sat, 26 Sep 2026 18:41:05 +0200
- Subject: [PATCH 19/22] URL: Fix parsing of query and fragment after a
++Subject: [PATCH 19/26] URL: Fix parsing of query and fragment after a
 + dot-component in path (#411)
 +MIME-Version: 1.0
 +Content-Type: text/plain; charset=UTF-8
 +Content-Transfer-Encoding: 8bit
 +
 +* URL: fixed dot segment terminators in path parsing.
 +
 +After a "." or ".." path segment the parser skipped the next code point
 +unconditionally.  For "?" and "#" this lost the delimiter, so the query
 +or the fragment became part of the path: "https://example.com/..#frag"
 +was parsed as "https://example.com/frag".  The fast path fix from #411
 +did not cover the slow path, which is taken after a code point that must
 +be percent-encoded, for example "https://example.com/café/..#frag".
 +
 +Also fixed in the same code:
 +- "\" after a dot segment in a special URL did not report
 +  invalid-reverse-solidus.
 +- The empty segment was lost in "//./c" and at the fast/slow path
 +  handoff ("//é").
 +- path.length drifted after dot segments and underflowed after ".." at
 +  the root, so a later ".." in the slow path did not shorten the path
 +  ("/a/b/../../../c/é/../../x" gave "/c/x").  The file host and path
 +  start states did not update it either.
 +- An invalid percent sequence in the fast path skipped the next two
 +  code points, so a following "/", "\", "?" or "#" was lost ("/%?q" put
 +  "?q" into the path).  Such a segment is now handed to the slow path,
 +  which checks "%" one code point at a time.
 +
 +Per reports from Tim Düsterhus (@TimWolla) and @NickSdot.
 +
 +This relates to #409 issue on GitHub.
 +This relates to #412 issue on GitHub.
 +This relates to #411 PR on GitHub.
 +
 +* URL: added regression tests for dot segments in path.
 +
 +Added tests for "." and ".." path segments followed by "?", "#", "\"
 +and the end of input, in both the fast and the slow path, for the
 +invalid-reverse-solidus validation error, and for path.length against
 +the serialized path.  Also added tests for invalid percent sequences
 +before dot segments and delimiters, both in parsing and in the pathname
 +setter.
 +
 +This relates to #409 issue on GitHub.
 +This relates to #412 issue on GitHub.
 +---
 + source/lexbor/url/url.c | 200 +++++++++++++++++++++++-----------------
 + 1 file changed, 113 insertions(+), 87 deletions(-)
 +
 +diff --git a/source/lexbor/url/url.c b/source/lexbor/url/url.c
 +index 9bfc2aa..55fe11f 100644
 +--- a/source/lexbor/url/url.c
 ++++ b/source/lexbor/url/url.c
 +@@ -546,15 +546,15 @@ lxb_url_path_slow_path(lxb_url_parser_t *parser, lxb_url_t *url,
 +                        const lxb_char_t *data, const lxb_char_t *end, bool bqs);
 +
 + static lxb_status_t
 +-lxb_url_path_try_dot(lxb_url_t *url, const lxb_char_t **begin,
 +-                     const lxb_char_t **last, const lxb_char_t **start,
 +-                     const lxb_char_t *end, bool bqs);
 ++lxb_url_path_try_dot(lxb_url_parser_t *parser, lxb_url_t *url,
 ++                     const lxb_char_t **begin, const lxb_char_t **last,
 ++                     const lxb_char_t **start, const lxb_char_t *end, bool bqs);
 +
 + static const lxb_char_t *
 +-lxb_url_path_dot_count(lxb_url_t *url, const lxb_char_t *p,
 +-                       const lxb_char_t *end, const lxb_char_t *sbuf_begin,
 +-                       lxb_char_t **sbuf, lxb_char_t **last, size_t *path_count,
 +-                       bool bqs);
 ++lxb_url_path_dot_count(lxb_url_parser_t *parser, lxb_url_t *url,
 ++                       const lxb_char_t *p, const lxb_char_t *end,
 ++                       const lxb_char_t *sbuf_begin, lxb_char_t **sbuf,
 ++                       lxb_char_t **last, size_t *path_count, bool bqs);
 +
 + static void
 + lxb_url_path_fix_windows_drive(lxb_url_t *url, lxb_char_t *sbuf,
 +@@ -990,23 +990,25 @@ lxb_url_path_shorten(lxb_url_t *url)
 +         }
 +     }
 +
 +-    if (url->path.str.data != NULL) {
 +-        url->path.length -= 1;
 ++    if (url->path.length == 0 || str->data == NULL) {
 ++        return;
 ++    }
 +
 +-        begin = str->data;
 +-        p = begin + str->length;
 ++    url->path.length -= 1;
 +
 +-        while (p > begin) {
 +-            p -= 1;
 ++    begin = str->data;
 ++    p = begin + str->length;
 +
 +-            if (*p == '/') {
 +-                *p = '\0';
 +-                break;
 +-            }
 +-        }
 ++    while (p > begin) {
 ++        p -= 1;
 +
 +-        str->length = p - begin;
 ++        if (*p == '/') {
 ++            *p = '\0';
 ++            break;
 ++        }
 +     }
 ++
 ++    str->length = p - begin;
 + }
 +
 + static lxb_status_t
 +@@ -2146,6 +2148,8 @@ again:
 +                     if (status != LXB_STATUS_OK) {
 +                         lxb_url_parse_return(orig_data, buf, status);
 +                     }
 ++
 ++                    url->path.length += 1;
 +                 }
 +             }
 +         }
 +@@ -2287,7 +2291,13 @@ again:
 +             && url->host.type == LXB_URL_HOST_TYPE__UNDEF)
 +         {
 +             status = lxb_url_path_append(url, mp_str.data, mp_str.length);
 +-            lxb_url_parse_return(orig_data, buf, status);
 ++            if (status != LXB_STATUS_OK) {
 ++                lxb_url_parse_return(orig_data, buf, status);
 ++            }
 ++
 ++            url->path.length += 1;
 ++
 ++            lxb_url_parse_return(orig_data, buf, LXB_STATUS_OK);
 +         }
 +
 +         lxb_url_parse_return(orig_data, buf, LXB_STATUS_OK);
 +@@ -2535,13 +2545,8 @@ lxb_url_path_fast_path(lxb_url_parser_t *parser, lxb_url_t *url,
 +                     || lexbor_str_res_map_hex[p[1]] == 0xff
 +                     || lexbor_str_res_map_hex[p[2]] == 0xff)
 +                 {
 +-                    status = lxb_url_log_append(parser, p,
 +-                                                LXB_URL_ERROR_TYPE_INVALID_URL_UNIT);
 +-                    if (status != LXB_STATUS_OK) {
 +-                        return NULL;
 +-                    }
 +-
 +-                    p = (end - p < 3) ? end - 1 : p + 2;
 ++                    /* Reprocess the segment without skipping delimiters. */
 ++                    goto slow;
 +                 }
 +                 else if (p[1] == '2' && (p[2] == 'e' || p[2] == 'E')
 +                          && (p == begin
 +@@ -2550,8 +2555,8 @@ lxb_url_path_fast_path(lxb_url_parser_t *parser, lxb_url_t *url,
 +                 {
 +                     url->path.length = count;
 +
 +-                    status = lxb_url_path_try_dot(url, &begin, &last,
 +-                                                  &p, end, bqs);
 ++                    status = lxb_url_path_try_dot(parser, url, &begin,
 ++                                                  &last, &p, end, bqs);
 +                     if (status != LXB_STATUS_OK) {
 +                         return NULL;
 +                     }
 +@@ -2589,8 +2594,8 @@ lxb_url_path_fast_path(lxb_url_parser_t *parser, lxb_url_t *url,
 +                 {
 +                     url->path.length = count;
 +
 +-                    status = lxb_url_path_try_dot(url, &begin, &last,
 +-                                                  &p, end, bqs);
 ++                    status = lxb_url_path_try_dot(parser, url, &begin,
 ++                                                  &last, &p, end, bqs);
 +                     if (status != LXB_STATUS_OK) {
 +                         return NULL;
 +                     }
 +@@ -2599,17 +2604,7 @@ lxb_url_path_fast_path(lxb_url_parser_t *parser, lxb_url_t *url,
 +                 }
 +             }
 +             else {
 +-                url->path.length = count;
 +-
 +-                if (last - 1 > begin) {
 +-                    status = lxb_url_path_append(url, begin,
 +-                                                 (last - 1) - begin);
 +-                    if (status != LXB_STATUS_OK) {
 +-                        return NULL;
 +-                    }
 +-                }
 +-
 +-                return lxb_url_path_slow_path(parser, url, last, end, bqs);
 ++                goto slow;
 +             }
 +         }
 +     }
 +@@ -2619,13 +2614,22 @@ lxb_url_path_fast_path(lxb_url_parser_t *parser, lxb_url_t *url,
 +         return NULL;
 +     }
 +
 +-    if (count == 0 || p != begin) {
 +-        count += 1;
 +-    }
 ++    url->path.length = count + 1;
 ++
 ++    return p;
 ++
 ++slow:
 +
 +     url->path.length = count;
 +
 +-    return p;
 ++    if (last > begin) {
 ++        status = lxb_url_path_append(url, begin, (last - 1) - begin);
 ++        if (status != LXB_STATUS_OK) {
 ++            return NULL;
 ++        }
 ++    }
 ++
 ++    return lxb_url_path_slow_path(parser, url, last, end, bqs);
 + }
 +
 + /*
 +@@ -2721,10 +2725,6 @@ lxb_url_path_slow_path(lxb_url_parser_t *parser, lxb_url_t *url,
 +
 +             count += 1;
 +             last = sbuf;
 +-
 +-            if (p + 1 >= end) {
 +-                count += 1;
 +-            }
 +         }
 +         else if (c == '\\' && lxb_url_is_special(url)) {
 +             status = lxb_url_log_append(parser, p,
 +@@ -2742,16 +2742,8 @@ lxb_url_path_slow_path(lxb_url_parser_t *parser, lxb_url_t *url,
 +
 +             count += 1;
 +             last = sbuf;
 +-
 +-            if (p + 1 >= end) {
 +-                count += 1;
 +-            }
 +         }
 +         else if ((c == '?' || c == '#') && bqs) {
 +-            lxb_url_path_fix_windows_drive(url, last, sbuf, count);
 +-
 +-            count += 1;
 +-            last = sbuf;
 +             break;
 +         }
 +         else if (lxb_url_map[c] & LXB_URL_MAP_PATH) {
 +@@ -2771,11 +2763,19 @@ lxb_url_path_slow_path(lxb_url_parser_t *parser, lxb_url_t *url,
 +         }
 +         else if (c == '.') {
 +             if (last == sbuf) {
 +-                tmp = lxb_url_path_dot_count(url, p, end, sbuf_begin,
 ++                tmp = lxb_url_path_dot_count(parser, url, p, end, sbuf_begin,
 +                                              &sbuf, &last, &count, bqs);
 ++                if (tmp == NULL) {
 ++                    goto failed;
 ++                }
 +
 +                 if (tmp != p) {
 +-                    p = tmp + 1;
 ++                    /* Skip '/' or '\', but leave '?' and '#' to the loop. */
 ++                    if (tmp < end && *tmp != '?' && *tmp != '#') {
 ++                        tmp += 1;
 ++                    }
 ++
 ++                    p = tmp;
 +                     continue;
 +                 }
 +             }
 +@@ -2800,11 +2800,19 @@ lxb_url_path_slow_path(lxb_url_parser_t *parser, lxb_url_t *url,
 +             else if (p[1] == '2' && (p[2] == 'e' || p[2] == 'E')
 +                      && last == sbuf)
 +             {
 +-                tmp = lxb_url_path_dot_count(url, p, end, sbuf_begin,
 ++                tmp = lxb_url_path_dot_count(parser, url, p, end, sbuf_begin,
 +                                              &sbuf, &last, &count, bqs);
 ++                if (tmp == NULL) {
 ++                    goto failed;
 ++                }
 +
 +                 if (tmp != p) {
 +-                    p = tmp + 1;
 ++                    /* Skip '/' or '\', but leave '?' and '#' to the loop. */
 ++                    if (tmp < end && *tmp != '?' && *tmp != '#') {
 ++                        tmp += 1;
 ++                    }
 ++
 ++                    p = tmp;
 +                     continue;
 +                 }
 +             }
 +@@ -2833,12 +2841,9 @@ lxb_url_path_slow_path(lxb_url_parser_t *parser, lxb_url_t *url,
 +         p += 1;
 +     }
 +
 +-    if (count == 0 || last < sbuf) {
 +-        lxb_url_path_fix_windows_drive(url, last, sbuf, count);
 +-        count += 1;
 +-    }
 ++    lxb_url_path_fix_windows_drive(url, last, sbuf, count);
 +
 +-    url->path.length = count;
 ++    url->path.length = count + 1;
 +
 +     status = lxb_url_path_append_wo_slash(url, sbuf_begin, sbuf - sbuf_begin);
 +     if (status != LXB_STATUS_OK) {
 +@@ -2861,13 +2866,12 @@ failed:
 + }
 +
 + static lxb_status_t
 +-lxb_url_path_try_dot(lxb_url_t *url, const lxb_char_t **begin,
 +-                     const lxb_char_t **last, const lxb_char_t **start,
 +-                     const lxb_char_t *end, bool bqs)
 ++lxb_url_path_try_dot(lxb_url_parser_t *parser, lxb_url_t *url,
 ++                     const lxb_char_t **begin, const lxb_char_t **last,
 ++                     const lxb_char_t **start, const lxb_char_t *end, bool bqs)
 + {
 +     unsigned count;
 +     lxb_char_t c;
 +-    lexbor_str_t *str;
 +     lxb_status_t status;
 +     const lxb_char_t *p;
 +
 +@@ -2912,40 +2916,54 @@ lxb_url_path_try_dot(lxb_url_t *url, const lxb_char_t **begin,
 +         }
 +     }
 +
 +-    if (p < end) {
 +-        *start = p;
 +-        *begin = p + 1;
 +-        *last = *begin;
 ++    if (count == 2) {
 ++        lxb_url_path_shorten(url);
 +     }
 +-    else {
 ++
 ++    if (p >= end) {
 ++        /* The caller appends the trailing empty segment. */
 +         *start = end - 1;
 +         *begin = end;
 +         *last = end;
 ++
 ++        return LXB_STATUS_OK;
 +     }
 +
 +-    if (count == 2) {
 +-        lxb_url_path_shorten(url);
 ++    if (*p == '?' || *p == '#') {
 ++        /* The caller's loop handles the delimiter and the empty segment. */
 ++        *start = p - 1;
 ++        *begin = p;
 ++        *last = p;
 ++
 ++        return LXB_STATUS_OK;
 +     }
 +-    else if (count == 1) {
 +-        str = &url->path.str;
 +
 +-        if (str->length > 0 && str->data[str->length - 1] == '/') {
 +-            str->length -= 1;
 +-            str->data[str->length] = '\0';
 ++    if (*p == '\\') {
 ++        status = lxb_url_log_append(parser, p,
 ++                                    LXB_URL_ERROR_TYPE_INVALID_REVERSE_SOLIDUS);
 ++        if (status != LXB_STATUS_OK) {
 ++            return status;
 +         }
 +     }
 +
 ++    /* Skip '/' or '\'. */
 ++
 ++    *start = p;
 ++    *begin = p + 1;
 ++    *last = *begin;
 ++
 +     return LXB_STATUS_OK;
 + }
 +
 + static const lxb_char_t *
 +-lxb_url_path_dot_count(lxb_url_t *url, const lxb_char_t *p,
 +-                       const lxb_char_t *end, const lxb_char_t *sbuf_begin,
 +-                       lxb_char_t **sbuf, lxb_char_t **last, size_t *path_count,
 +-                       bool bqs)
 ++lxb_url_path_dot_count(lxb_url_parser_t *parser, lxb_url_t *url,
 ++                       const lxb_char_t *p, const lxb_char_t *end,
 ++                       const lxb_char_t *sbuf_begin, lxb_char_t **sbuf,
 ++                       lxb_char_t **last, size_t *path_count, bool bqs)
 + {
 +     unsigned count;
 +     lxb_char_t c, *last_p;
 ++    lxb_status_t status;
 +     const lxb_char_t *begin;
 +
 +     count = 0;
 +@@ -2982,6 +3000,14 @@ lxb_url_path_dot_count(lxb_url_t *url, const lxb_char_t *p,
 +         return begin;
 +     }
 +
 ++    if (p < end && *p == '\\') {
 ++        status = lxb_url_log_append(parser, p,
 ++                                    LXB_URL_ERROR_TYPE_INVALID_REVERSE_SOLIDUS);
 ++        if (status != LXB_STATUS_OK) {
 ++            return NULL;
 ++        }
 ++    }
 ++
 +     if (url->scheme.type == LXB_URL_SCHEMEL_TYPE_FILE
 +         && *path_count == 1
 +         && lxb_url_normalized_windows_drive_letter(sbuf_begin + 1, *last - 1))
diff --cc ext/lexbor/patches/0020-URL-Keep-replacement-file-drive-paths-hierarchical-4.patch
index 22d897de5c6,00000000000..f4a861c022a
mode 100644,000000..100644
--- a/ext/lexbor/patches/0020-URL-Keep-replacement-file-drive-paths-hierarchical-4.patch
+++ b/ext/lexbor/patches/0020-URL-Keep-replacement-file-drive-paths-hierarchical-4.patch
@@@ -1,23 -1,0 +1,23 @@@
 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
 +From: =?UTF-8?q?M=C3=A1t=C3=A9=20Kocsis?= <kocsismate@woohoolabs.com>
 +Date: Mon, 21 Sep 2026 20:01:43 +0200
- Subject: [PATCH 20/22] URL: Keep replacement file drive paths hierarchical
++Subject: [PATCH 20/26] URL: Keep replacement file drive paths hierarchical
 + (#423)
 +
 +WHATWG file state (https://url.spec.whatwg.org/#file-state) step 4.4.3.2 resets the path to an empty list. Do not mark it opaque, as that makes subsequent pathname updates silently do nothing.
 +---
 + source/lexbor/url/url.c | 1 -
 + 1 file changed, 1 deletion(-)
 +
 +diff --git a/source/lexbor/url/url.c b/source/lexbor/url/url.c
 +index 55fe11f..2231816 100644
 +--- a/source/lexbor/url/url.c
 ++++ b/source/lexbor/url/url.c
 +@@ -2099,7 +2099,6 @@ again:
 +                 }
 +
 +                 lxb_url_path_set_null(url);
 +-                url->path.opaque = true;
 +             }
 +         }
 +
diff --cc ext/lexbor/patches/0021-URL-normalize-output-encoding-for-percent-encoding.patch
index c1fe49461a2,00000000000..2e2f4331a51
mode 100644,000000..100644
--- a/ext/lexbor/patches/0021-URL-normalize-output-encoding-for-percent-encoding.patch
+++ b/ext/lexbor/patches/0021-URL-normalize-output-encoding-for-percent-encoding.patch
@@@ -1,80 -1,0 +1,80 @@@
 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
 +From: Alexander Borisov <lex.borisov@gmail.com>
 +Date: Thu, 24 Sep 2026 15:05:51 +0300
- Subject: [PATCH 21/22] URL: normalize output encoding for percent-encoding.
++Subject: [PATCH 21/26] URL: normalize output encoding for percent-encoding.
 +
 +---
 + source/lexbor/url/url.c | 34 +++++++++++++++++++++++++---------
 + 1 file changed, 25 insertions(+), 9 deletions(-)
 +
 +diff --git a/source/lexbor/url/url.c b/source/lexbor/url/url.c
 +index 2231816..146f0bd 100644
 +--- a/source/lexbor/url/url.c
 ++++ b/source/lexbor/url/url.c
 +@@ -1228,6 +1228,26 @@ lxb_url_encoding_init(const lxb_encoding_data_t *encoding,
 +     (void) lxb_encoding_encode_init_single(encode, encoding);
 + }
 +
 ++/*
 ++ * https://encoding.spec.whatwg.org/#get-an-output-encoding
 ++ */
 ++lxb_inline lxb_encoding_t
 ++lxb_url_output_encoding(lxb_encoding_t encoding)
 ++{
 ++    switch (encoding) {
 ++        case LXB_ENCODING_DEFAULT:
 ++        case LXB_ENCODING_AUTO:
 ++        case LXB_ENCODING_UNDEFINED:
 ++        case LXB_ENCODING_REPLACEMENT:
 ++        case LXB_ENCODING_UTF_16BE:
 ++        case LXB_ENCODING_UTF_16LE:
 ++            return LXB_ENCODING_UTF_8;
 ++
 ++        default:
 ++            return encoding;
 ++    }
 ++}
 ++
 + static bool
 + lxb_url_start_windows_drive_letter(const lxb_char_t *data,
 +                                    const lxb_char_t *end)
 +@@ -1372,12 +1392,7 @@ lxb_url_parse_basic_h(lxb_url_parser_t *parser, lxb_url_t *url,
 +         state = override_state;
 +     }
 +
 +-    if (encoding <= LXB_ENCODING_UNDEFINED
 +-        || encoding == LXB_ENCODING_UTF_16BE
 +-        || encoding == LXB_ENCODING_UTF_16LE)
 +-    {
 +-        encoding = LXB_ENCODING_UTF_8;
 +-    }
 ++    encoding = lxb_url_output_encoding(encoding);
 +
 +     enc = lxb_encoding_data(encoding);
 +     if (enc == NULL) {
 +@@ -3221,7 +3236,7 @@ lxb_url_percent_encode_after_encoding(const lxb_char_t *data,
 +     const lxb_char_t *buf_end = buf + sizeof(buffer);
 +     static const lexbor_str_t esc_str = lexbor_str("%26%23");
 +
 +-    if (encoding->encoding == LXB_ENCODING_UTF_8) {
 ++    if (lxb_url_output_encoding(encoding->encoding) == LXB_ENCODING_UTF_8) {
 +         return lxb_url_percent_encode_after_utf_8(data, end, str, mraw,
 +                                                   enmap, space_as_plus);
 +     }
 +@@ -3256,13 +3271,14 @@ lxb_url_percent_encode_after_encoding(const lxb_char_t *data,
 +         len = encoding->encode_single(&encode, &buf, buf_end, cp);
 +
 +         if (len < LXB_ENCODING_ENCODE_OK) {
 +-            size = lexbor_conv_int64_to_data((int64_t) cp, buf, buf_end - buf);
 ++            size = lexbor_conv_int64_to_data((int64_t) cp, buffer,
 ++                                             sizeof(buffer));
 +
 +             if (lexbor_str_append(str, mraw, esc_str.data, esc_str.length) == NULL) {
 +                 return LXB_STATUS_ERROR_MEMORY_ALLOCATION;
 +             }
 +
 +-            if (lexbor_str_append(str, mraw, buf, size) == NULL) {
 ++            if (lexbor_str_append(str, mraw, buffer, size) == NULL) {
 +                 return LXB_STATUS_ERROR_MEMORY_ALLOCATION;
 +             }
 +
diff --cc ext/lexbor/patches/0022-HTML-fixed-crash-use-after-free-and-leaks-on-allocat.patch
index 14f242091a5,00000000000..46c06e28840
mode 100644,000000..100644
--- a/ext/lexbor/patches/0022-HTML-fixed-crash-use-after-free-and-leaks-on-allocat.patch
+++ b/ext/lexbor/patches/0022-HTML-fixed-crash-use-after-free-and-leaks-on-allocat.patch
@@@ -1,94 -1,0 +1,94 @@@
 +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
 +From: sjanel <67502353+sjanel@users.noreply.github.com>
 +Date: Wed, 11 Nov 2026 20:26:42 +0100
- Subject: [PATCH 22/22] HTML: fixed crash, use-after-free and leaks on
++Subject: [PATCH 22/26] HTML: fixed crash, use-after-free and leaks on
 + allocation failure in document create and parse (#448)
 +
 +HTML: fixed crash, use-after-free and leaks on allocation failure.
 +---
 + source/lexbor/dom/interfaces/document.c  | 21 +++++++++++++--------
 + source/lexbor/html/interfaces/document.c |  2 +-
 + source/lexbor/html/parser.c              |  6 ++++++
 + 3 files changed, 20 insertions(+), 9 deletions(-)
 +
 +diff --git a/source/lexbor/dom/interfaces/document.c b/source/lexbor/dom/interfaces/document.c
 +index 43eeba0..6428354 100644
 +--- a/source/lexbor/dom/interfaces/document.c
 ++++ b/source/lexbor/dom/interfaces/document.c
 +@@ -124,6 +124,12 @@ lxb_dom_document_init(lxb_dom_document_t *document, lxb_dom_document_t *owner,
 +
 +     document->css = NULL;
 +
 ++    /*
 ++     * Set before the allocations: lxb_dom_document_destroy() frees a document
 ++     * that owns itself, and dereferences the owner of any other.
 ++     */
 ++    node->owner_document = document;
 ++
 +     /* For nodes */
 +     document->mraw = lexbor_mraw_create();
 +     status = lexbor_mraw_init(document->mraw, (4096 * 8));
 +@@ -166,18 +172,17 @@ lxb_dom_document_init(lxb_dom_document_t *document, lxb_dom_document_t *owner,
 +         goto failed;
 +     }
 +
 +-    node->owner_document = document;
 +-
 +     return LXB_STATUS_OK;
 +
 + failed:
 +
 +-    lexbor_mraw_destroy(document->mraw, true);
 +-    lexbor_mraw_destroy(document->text, true);
 +-    lexbor_hash_destroy(document->tags, true);
 +-    lexbor_hash_destroy(document->ns, true);
 +-    lexbor_hash_destroy(document->attrs, true);
 +-    lexbor_hash_destroy(document->prefix, true);
 ++    /* Reset, so that lxb_dom_document_destroy() does not free them again. */
 ++    document->mraw = lexbor_mraw_destroy(document->mraw, true);
 ++    document->text = lexbor_mraw_destroy(document->text, true);
 ++    document->tags = lexbor_hash_destroy(document->tags, true);
 ++    document->ns = lexbor_hash_destroy(document->ns, true);
 ++    document->attrs = lexbor_hash_destroy(document->attrs, true);
 ++    document->prefix = lexbor_hash_destroy(document->prefix, true);
 +
 +     return LXB_STATUS_ERROR;
 + }
 +diff --git a/source/lexbor/html/interfaces/document.c b/source/lexbor/html/interfaces/document.c
 +index b40c6c8..5059050 100644
 +--- a/source/lexbor/html/interfaces/document.c
 ++++ b/source/lexbor/html/interfaces/document.c
 +@@ -278,7 +278,7 @@ lxb_html_document_parser_prepare(lxb_html_document_t *document)
 +         status = lxb_html_parser_init(doc->parser);
 +
 +         if (status != LXB_STATUS_OK) {
 +-            lxb_html_parser_destroy(doc->parser);
 ++            doc->parser = lxb_html_parser_destroy(doc->parser);
 +             return status;
 +         }
 +
 +diff --git a/source/lexbor/html/parser.c b/source/lexbor/html/parser.c
 +index 7d05104..62e7370 100644
 +--- a/source/lexbor/html/parser.c
 ++++ b/source/lexbor/html/parser.c
 +@@ -40,7 +40,12 @@ lxb_html_parser_init(lxb_html_parser_t *parser)
 +     parser->tkz = lxb_html_tokenizer_create();
 +     lxb_status_t status = lxb_html_tokenizer_init(parser->tkz);
 +
 ++    /*
 ++     * A tokenizer or a tree that failed to initialize has no reference yet,
 ++     * so lxb_html_parser_destroy() could not release it: destroy it here.
 ++     */
 +     if (status != LXB_STATUS_OK) {
 ++        parser->tkz = lxb_html_tokenizer_destroy(parser->tkz);
 +         return status;
 +     }
 +
 +@@ -51,6 +56,7 @@ lxb_html_parser_init(lxb_html_parser_t *parser)
 +     status = lxb_html_tree_init(parser->tree, parser->tkz);
 +
 +     if (status != LXB_STATUS_OK) {
 ++        parser->tree = lxb_html_tree_destroy(parser->tree);
 +         return status;
 +     }
 +
diff --cc ext/lexbor/patches/0023-CSS-Syntax-fixed-non-ASCII-ident-code-point-ranges.patch
index 00000000000,9a2059fab5c..280e7839582
mode 000000,100644..100644
--- a/ext/lexbor/patches/0023-CSS-Syntax-fixed-non-ASCII-ident-code-point-ranges.patch
+++ b/ext/lexbor/patches/0023-CSS-Syntax-fixed-non-ASCII-ident-code-point-ranges.patch
@@@ -1,0 -1,78 +1,78 @@@
+ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+ From: Alexander Borisov <lex.borisov@gmail.com>
+ Date: Sat, 20 Jun 2026 15:39:44 +0400
 -Subject: [PATCH 09/12] CSS::Syntax: fixed non-ASCII ident code point ranges.
++Subject: [PATCH 23/26] CSS::Syntax: fixed non-ASCII ident code point ranges.
+
+ By specification https://drafts.csswg.org/css-syntax/#non-ascii-ident-code-point.
+
+ Per report from Jon Surrell (@sirreal).
+
+ This relates to #382 issue on GitHub.
+ ---
+  source/lexbor/css/syntax/state.c | 41 ++++++++++++++++++++++----------
+  1 file changed, 28 insertions(+), 13 deletions(-)
+
+ diff --git a/source/lexbor/css/syntax/state.c b/source/lexbor/css/syntax/state.c
+ index a93731e..a011c5a 100644
+ --- a/source/lexbor/css/syntax/state.c
+ +++ b/source/lexbor/css/syntax/state.c
+ @@ -165,31 +165,46 @@ lxb_css_syntax_state_non_ascii(lxb_codepoint_t cp)
+      /* This code is generated by the file utils/lexbor/css/syntax/non_ascii.pl */
+
+      /* Begin */
+ -    if (cp <= 0x2FEF) {
+ -        if (cp <= 0x1FFF) {
+ -            if (cp >= 0x00F8 && cp < 0x037D) {
+ +    if (cp <= 0x218F) {
+ +        if (cp <= 0x00F6) {
+ +            if (cp >= 0x00B7 && cp <= 0x00B7) {
+                  return true;
+              }
+ -            else if (cp >= 0x037F) {
+ -                return true;
+ +            else if (cp >= 0x00C0) {
+ +                if (cp <= 0x00D6) {
+ +                    return true;
+ +                }
+ +                else if (cp >= 0x00D8) {
+ +                    return true;
+ +                }
+              }
+          }
+ -        else if (cp >= 0x2070) {
+ -            if (cp <= 0x218F) {
+ +        else if (cp >= 0x00F8) {
+ +            if (cp <= 0x037D) {
+                  return true;
+              }
+ -            else if (cp >= 0x2C00) {
+ -                return true;
+ +            else if (cp >= 0x037F) {
+ +                if (cp <= 0x1FFF) {
+ +                    return true;
+ +                }
+ +                else if (cp >= 0x2070) {
+ +                    return true;
+ +                }
+              }
+          }
+      }
+ -    else if (cp >= 0x3001) {
+ +    else if (cp >= 0x2C00) {
+          if (cp <= 0xFDCF) {
+ -            if (cp <= 0xDFFF) {
+ +            if (cp <= 0x2FEF) {
+                  return true;
+              }
+ -            else if (cp >= 0xF900) {
+ -                return true;
+ +            else if (cp >= 0x3001) {
+ +                if (cp <= 0xDFFF) {
+ +                    return true;
+ +                }
+ +                else if (cp >= 0xF900) {
+ +                    return true;
+ +                }
+              }
+          }
+          else if (cp >= 0xFDF0) {
diff --cc ext/lexbor/patches/0024-iCSS-Syntax-fixed-U-FFFD-replacement-boundaries-for-.patch
index 00000000000,7306fd5e4d7..dbafbc7b0cc
mode 000000,100644..100644
--- a/ext/lexbor/patches/0024-iCSS-Syntax-fixed-U-FFFD-replacement-boundaries-for-.patch
+++ b/ext/lexbor/patches/0024-iCSS-Syntax-fixed-U-FFFD-replacement-boundaries-for-.patch
@@@ -1,0 -1,201 +1,201 @@@
+ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+ From: Alexander Borisov <lex.borisov@gmail.com>
+ Date: Wed, 8 Jul 2026 20:10:47 +0300
 -Subject: [PATCH 10/12] iCSS::Syntax: fixed U+FFFD replacement boundaries for
++Subject: [PATCH 24/26] iCSS::Syntax: fixed U+FFFD replacement boundaries for
+  UTF-8.
+
+ The tokenizer replaced ill-formed UTF-8 with U+FFFD at boundaries that do
+ not match the specification and browsers. A truncated sequence with valid
+ continuation bytes (E2 8C) produced two U+FFFD instead of one, and a UTF-8
+ encoded surrogate (ED A0 80) produced one U+FFFD instead of three.
+
+ By specification, each maximal subpart of an ill-formed subsequence must
+ be replaced with a single U+FFFD:
+ https://drafts.csswg.org/css-syntax/#input-byte-stream
+ https://encoding.spec.whatwg.org/#utf-8-decoder
+
+ Per report from Jon Surrell (@sirreal).
+
+ This closes #390 issue on GitHub.
+ ---
+  source/lexbor/css/syntax/state.c | 129 +++++++++----------------------
+  1 file changed, 38 insertions(+), 91 deletions(-)
+
+ diff --git a/source/lexbor/css/syntax/state.c b/source/lexbor/css/syntax/state.c
+ index a011c5a..abcf930 100644
+ --- a/source/lexbor/css/syntax/state.c
+ +++ b/source/lexbor/css/syntax/state.c
+ @@ -67,21 +67,13 @@
+      }
+
+  #define LXB_CSS_SYNTAX_UTF_8_UP_80_BLOCK(tkz, begin, data, end)               \
+ +        const lxb_char_t *_bad = data;                                        \
+          lxb_codepoint_t cp = lxb_css_syntax_state_decode_utf_8_up_80(&data,   \
+                                                                       end);    \
+                                                                                \
+          if (cp == LXB_CSS_SYNTAX_ERROR_CODEPOINT) {                           \
+ -            lxb_css_syntax_buffer_append_m(tkz, begin, data - begin);         \
+ -            /* U+FFFD REPLACEMENT CHARACTER */                                \
+ -            lxb_css_syntax_buffer_append_m(tkz, "\uFFFD",                     \
+ -                                           lxb_css_syntax_replacement_length);\
+ -            data += 1;                                                        \
+ -            begin = data;                                                     \
+ -        }                                                                     \
+ -        /* Surrogate U+D800 to U+DFFF. */                                     \
+ -        else if (cp >= 0xD800 && cp <= 0xDFFF) {                              \
+ -            lxb_css_syntax_buffer_append_m(tkz, begin,                        \
+ -                                           (data - begin) - 3);               \
+ +            /* Flush the run before the ill-formed sequence, then U+FFFD. */  \
+ +            lxb_css_syntax_buffer_append_m(tkz, begin, _bad - begin);         \
+              /* U+FFFD REPLACEMENT CHARACTER */                                \
+              lxb_css_syntax_buffer_append_m(tkz, "\uFFFD",                     \
+                                             lxb_css_syntax_replacement_length);\
+ @@ -580,14 +572,6 @@ lxb_css_syntax_state_string(lxb_css_syntax_tokenizer_t *tkz, lxb_css_syntax_toke
+                              cp = lxb_css_syntax_state_decode_utf_8_up_80(&data, end);
+
+                              if (cp == LXB_CSS_SYNTAX_ERROR_CODEPOINT) {
+ -                                /* U+FFFD REPLACEMENT CHARACTER */
+ -                                lxb_css_syntax_buffer_append_m(tkz, "\uFFFD",
+ -                                                               lxb_css_syntax_replacement_length);
+ -                                data += 1;
+ -                                begin = data;
+ -                            }
+ -                            /* Surrogate U+D800 to U+DFFF. */
+ -                            else if (cp >= 0xD800 && cp <= 0xDFFF) {
+                                  /* U+FFFD REPLACEMENT CHARACTER */
+                                  lxb_css_syntax_buffer_append_m(tkz, "\uFFFD",
+                                                                 lxb_css_syntax_replacement_length);
+ @@ -1785,98 +1769,61 @@ static lxb_codepoint_t
+  lxb_css_syntax_state_decode_utf_8_up_80(const lxb_char_t **data,
+                                          const lxb_char_t *end)
+  {
+ -    lxb_char_t ch;
+ +    lxb_char_t ch, lower, upper;
+ +    unsigned needed;
+      const lxb_char_t *p;
+      lxb_codepoint_t cp;
+
+ +    /*
+ +     * WHATWG UTF-8 decoder: https://encoding.spec.whatwg.org/#utf-8-decoder
+ +     */
+ +
+      p = *data;
+ -    ch = *p;
+ +    ch = *p++;
+
+      if (ch <= 0xDF) {
+ -        if (ch < 0xC2 || p + 1 >= end) {
+ +        if (ch < 0xC2) {
+ +            *data = p;
+              return LXB_CSS_SYNTAX_ERROR_CODEPOINT;
+          }
+
+ +        needed = 1;
+ +        lower = 0x80;
+ +        upper = 0xBF;
+          cp = ch & 0x1F;
+ -
+ -        if (p[1] < 0x80 || p[1] > 0xBF) {
+ -            return LXB_CSS_SYNTAX_ERROR_CODEPOINT;
+ -        }
+ -
+ -        cp = (cp << 6) | (p[1] & 0x3F);
+ -
+ -        *data += 2;
+      }
+ -    else if (ch < 0xF0) {
+ +    else if (ch <= 0xEF) {
+ +        needed = 2;
+ +        lower = (ch == 0xE0) ? 0xA0 : 0x80;
+ +        upper = (ch == 0xED) ? 0x9F : 0xBF;
+          cp = ch & 0x0F;
+ -
+ -        if (p + 2 >= end) {
+ -            return LXB_CSS_SYNTAX_ERROR_CODEPOINT;
+ -        }
+ -
+ -        if (ch == 0xE0) {
+ -            if (p[1] < 0xA0 || p[1] > 0xBF) {
+ -                return LXB_CSS_SYNTAX_ERROR_CODEPOINT;
+ -            }
+ -        }
+ -
+ -        /*
+ -         * We returning surrogate pair!
+ -         */
+ -/*
+ -        else if (ch == 0xED) {
+ -            if (p[1] < 0x80 || p[1] > 0x9F) {
+ -                return LXB_CSS_SYNTAX_ERROR_CODEPOINT;
+ -            }
+ -        }
+ - */
+ -        else if (p[1] < 0x80 || p[1] > 0xBF) {
+ -            return LXB_CSS_SYNTAX_ERROR_CODEPOINT;
+ -        }
+ -
+ -        if (p[2] < 0x80 || p[2] > 0xBF) {
+ -            return LXB_CSS_SYNTAX_ERROR_CODEPOINT;
+ -        }
+ -
+ -        cp = (cp << 6) | (p[1] & 0x3F);
+ -        cp = (cp << 6) | (p[2] & 0x3F);
+ -
+ -        *data += 3;
+      }
+ -    else if (ch < 0xF5) {
+ +    else if (ch <= 0xF4) {
+ +        needed = 3;
+ +        lower = (ch == 0xF0) ? 0x90 : 0x80;
+ +        upper = (ch == 0xF4) ? 0x8F : 0xBF;
+          cp = ch & 0x07;
+ +    }
+ +    else {
+ +        /* 0xF5..0xFF: an invalid lead byte. */
+ +        *data = p;
+ +        return LXB_CSS_SYNTAX_ERROR_CODEPOINT;
+ +    }
+
+ -        if (p + 3 >= end) {
+ -            return LXB_CSS_SYNTAX_ERROR_CODEPOINT;
+ -        }
+ -
+ -        if (ch == 0xF0) {
+ -            if (p[1] < 0x90 || p[1] > 0xBF) {
+ -                return LXB_CSS_SYNTAX_ERROR_CODEPOINT;
+ -            }
+ -        }
+ -        else if (ch == 0xF4) {
+ -            if (p[1] < 0x80 || p[1] > 0x8F) {
+ -                return LXB_CSS_SYNTAX_ERROR_CODEPOINT;
+ -            }
+ -        }
+ -        else if (p[1] < 0x80 || p[1] > 0xBF) {
+ -            return LXB_CSS_SYNTAX_ERROR_CODEPOINT;
+ -        }
+ -
+ -        if ((p[2] < 0x80 || p[2] > 0xBF) || (p[3] < 0x80 || p[3] > 0xBF)) {
+ +    do {
+ +        if (p >= end || *p < lower || *p > upper) {
+ +            *data = p;
+              return LXB_CSS_SYNTAX_ERROR_CODEPOINT;
+          }
+
+ -        cp = (cp << 6) | (p[1] & 0x3F);
+ -        cp = (cp << 6) | (p[2] & 0x3F);
+ -        cp = (cp << 6) | (p[3] & 0x3F);
+ +        cp = (cp << 6) | (*p++ & 0x3F);
+
+ -        *data += 4;
+ -    }
+ -    else {
+ -        return LXB_CSS_SYNTAX_ERROR_CODEPOINT;
+ +        lower = 0x80;
+ +        upper = 0xBF;
+      }
+ +    while (--needed != 0);
+ +
+ +    *data = p;
+
+      return cp;
+  }
diff --cc ext/lexbor/patches/0025-CSS-Syntax-fixed-UTF-8-escapes-in-ident-sequences.patch
index 00000000000,d95a8003121..8f90693abc4
mode 000000,100644..100644
--- a/ext/lexbor/patches/0025-CSS-Syntax-fixed-UTF-8-escapes-in-ident-sequences.patch
+++ b/ext/lexbor/patches/0025-CSS-Syntax-fixed-UTF-8-escapes-in-ident-sequences.patch
@@@ -1,0 -1,60 +1,60 @@@
+ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+ From: Alexander Borisov <lex.borisov@gmail.com>
+ Date: Thu, 9 Jul 2026 23:24:05 +0300
 -Subject: [PATCH 11/12] CSS::Syntax: fixed UTF-8 escapes in ident sequences.
++Subject: [PATCH 25/26] CSS::Syntax: fixed UTF-8 escapes in ident sequences.
+ MIME-Version: 1.0
+ Content-Type: text/plain; charset=UTF-8
+ Content-Transfer-Encoding: 8bit
+
+ Non-hex escapes consumed only the first byte of a UTF-8 sequence and used it
+ as a code point. Because of this, "a\é" became "aÃ�" instead of "aé".
+ The same issue affected unquoted URL tokens.
+ ---
+  source/lexbor/css/syntax/state.c | 20 +++++++++++++++++++-
+  1 file changed, 19 insertions(+), 1 deletion(-)
+
+ diff --git a/source/lexbor/css/syntax/state.c b/source/lexbor/css/syntax/state.c
+ index abcf930..a1db76a 100644
+ --- a/source/lexbor/css/syntax/state.c
+ +++ b/source/lexbor/css/syntax/state.c
+ @@ -628,6 +628,17 @@ lxb_css_syntax_state_hash(lxb_css_syntax_tokenizer_t *tkz,
+          return lxb_css_syntax_state_delim_set(token, data - 1, '#');
+      }
+
+ +    if (*data >= 0x80) {
+ +        begin = data;
+ +
+ +        if (lxb_css_syntax_state_start_ident_utf_8_80(&data, end)) {
+ +            data = begin;
+ +            goto hash;
+ +        }
+ +
+ +        return lxb_css_syntax_state_delim_set(token, begin - 1, '#');
+ +    }
+ +
+      if (lxb_css_syntax_res_name_map[*data] == 0x00) {
+          if (*data == 0x00) {
+              goto hash;
+ @@ -1201,6 +1212,7 @@ lxb_css_syntax_state_consume_ident(lxb_css_syntax_tokenizer_t *tkz,
+          else {
+              LXB_CSS_SYNTAX_UTF_8_UP_80_BLOCK(tkz, begin, data, end)
+              else if (!lxb_css_syntax_state_non_ascii(cp)) {
+ +                data = _bad;
+                  break;
+              }
+          }
+ @@ -1629,7 +1641,13 @@ lxb_css_syntax_state_escaped(lxb_css_syntax_tokenizer_t *tkz,
+
+          if (lexbor_str_res_map_hex[*data] == 0xFF) {
+              if (count == 0) {
+ -                cp = (lxb_codepoint_t) *data++;
+ +                if (*data < 0x80) {
+ +                    cp = (lxb_codepoint_t) *data++;
+ +                }
+ +                else {
+ +                    cp = lxb_css_syntax_state_decode_utf_8_up_80(&data, end);
+ +                }
+ +
+                  goto done;
+              }
+
diff --cc ext/lexbor/patches/0026-CSS-Syntax-fixed-non-ASCII-ident-code-points.patch
index 00000000000,bfdfef77b60..66046794646
mode 000000,100644..100644
--- a/ext/lexbor/patches/0026-CSS-Syntax-fixed-non-ASCII-ident-code-points.patch
+++ b/ext/lexbor/patches/0026-CSS-Syntax-fixed-non-ASCII-ident-code-points.patch
@@@ -1,0 -1,102 +1,102 @@@
+ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+ From: Alexander Borisov <lex.borisov@gmail.com>
+ Date: Fri, 10 Jul 2026 00:39:54 +0300
 -Subject: [PATCH 12/12] CSS::Syntax: fixed non-ASCII ident code points.
++Subject: [PATCH 26/26] CSS::Syntax: fixed non-ASCII ident code points.
+
+ Updated generated non-ASCII ident ranges to match CSS Syntax:
+ included U+200C/U+200D and U+203F/U+2040, and stopped the
+ U+3001 range at U+D7FF to exclude surrogate code points.
+ ---
+  source/lexbor/css/syntax/state.c | 45 ++++++++++++++++++--------------
+  1 file changed, 25 insertions(+), 20 deletions(-)
+
+ diff --git a/source/lexbor/css/syntax/state.c b/source/lexbor/css/syntax/state.c
+ index a1db76a..5b694e9 100644
+ --- a/source/lexbor/css/syntax/state.c
+ +++ b/source/lexbor/css/syntax/state.c
+ @@ -149,15 +149,10 @@ lxb_css_syntax_state_valid_escape(const lxb_char_t *data,
+  lxb_inline bool
+  lxb_css_syntax_state_non_ascii(lxb_codepoint_t cp)
+  {
+ -    /*
+ -     * Actually here the comparison should be to U+D7FF.
+ -     * But we capture surrogate pairs, they will be further converted to 0xFFFD.
+ -     */
+ -
+      /* This code is generated by the file utils/lexbor/css/syntax/non_ascii.pl */
+
+      /* Begin */
+ -    if (cp <= 0x218F) {
+ +    if (cp <= 0x2040) {
+          if (cp <= 0x00F6) {
+              if (cp >= 0x00B7 && cp <= 0x00B7) {
+                  return true;
+ @@ -172,36 +167,46 @@ lxb_css_syntax_state_non_ascii(lxb_codepoint_t cp)
+              }
+          }
+          else if (cp >= 0x00F8) {
+ -            if (cp <= 0x037D) {
+ -                return true;
+ +            if (cp <= 0x1FFF) {
+ +                if (cp <= 0x037D) {
+ +                    return true;
+ +                }
+ +                else if (cp >= 0x037F) {
+ +                    return true;
+ +                }
+              }
+ -            else if (cp >= 0x037F) {
+ -                if (cp <= 0x1FFF) {
+ +            else if (cp >= 0x200C) {
+ +                if (cp <= 0x200D) {
+                      return true;
+                  }
+ -                else if (cp >= 0x2070) {
+ +                else if (cp >= 0x203F) {
+                      return true;
+                  }
+              }
+          }
+      }
+ -    else if (cp >= 0x2C00) {
+ -        if (cp <= 0xFDCF) {
+ -            if (cp <= 0x2FEF) {
+ +    else if (cp >= 0x2070) {
+ +        if (cp <= 0xD7FF) {
+ +            if (cp <= 0x218F) {
+                  return true;
+              }
+ -            else if (cp >= 0x3001) {
+ -                if (cp <= 0xDFFF) {
+ +            else if (cp >= 0x2C00) {
+ +                if (cp <= 0x2FEF) {
+                      return true;
+                  }
+ -                else if (cp >= 0xF900) {
+ +                else if (cp >= 0x3001) {
+                      return true;
+                  }
+              }
+          }
+ -        else if (cp >= 0xFDF0) {
+ +        else if (cp >= 0xF900) {
+              if (cp <= 0xFFFD) {
+ -                return true;
+ +                if (cp <= 0xFDCF) {
+ +                    return true;
+ +                }
+ +                else if (cp >= 0xFDF0) {
+ +                    return true;
+ +                }
+              }
+              else if (cp >= 0x10000) {
+                  if (cp <= 0x10FFFF) {
+ @@ -212,7 +217,7 @@ lxb_css_syntax_state_non_ascii(lxb_codepoint_t cp)
+      }
+      /* End */
+
+ -    return cp == 0x200C || cp == 0x200D || cp == 0x203F || cp == 0x2040;
+ +    return false;
+  }
+
+  lxb_inline bool