Skip to content

Dom: querySelector() rejects a selector whose identifier starts with a non-ASCII character, like #été #25501

Open

Description

@phcorp

Description

A selector whose identifier starts with a non-ASCII character is rejected:

<?php
$doc = Dom\HTMLDocument::createFromString('<p id="été">a</p><p class="élan">b</p>', LIBXML_NOERROR);
var_dump($doc->querySelector('#\e9 t\e9')?->textContent);
var_dump($doc->querySelector('#été')?->textContent);

Resulted in this output:

string(1) "a"

Fatal error: Uncaught DOMException: Invalid selector (Selectors. Unexpected token: té)

But I expected this output instead:

string(1) "a"
string(1) "a"

CSS Syntax allows any code point from U+0080 in an ident and a hash token, and browsers accept document.querySelector('#été'). .élan fails the same way; a name whose non-ASCII character is not the first one, like .café, works, and so does the escaped form above.

The bundled lexbor tokenizer checks its ASCII name table before the non-ASCII branch in lxb_css_syntax_state_hash() (ext/lexbor/lexbor/css/syntax/state.c, the same on PHP-8.5 and master). lexbor fixed it after its last release, in lexbor/lexbor@ce777c50f2 ("CSS::Syntax: fixed non-ASCII ident code points") and lexbor/lexbor@3a5217afde ("CSS::Syntax: fixed non-ASCII ident code point ranges"); backporting them would fix it.

PHP Version

PHP 8.5.12 (lexbor 2.7.0); master has the same code.

Operating System

macOS (not OS-specific)

Activity

  1. self-assigned this
    on Nov 17, 2026
  2. added 2 commits that reference this issue on Nov 17, 2026
    fa660a6
    268d933
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions