Skip to content

Class and ID selector's prefixed with hyphen returning null with document.querySelector #3620

@coxrichuk

Description

@coxrichuk

Basic info:

  • Node.js version: 18.18.2
  • jsdom version: ^22.1.0

Minimal reproduction case

const { JSDOM } = require('jsdom');
const { document } = (new JSDOM('')).window;

try {
     console.log(document.querySelector('#-123')); // Returns null - incorrect
     console.log(document.querySelector('.-123')); // Returns null - incorrect
} catch(err) {
     console.error(err); // Should throw error
}

How does similar code behave in browsers?

https://jsbin.com/coromew/edit?js,console,output

Verified Chrome / Firefox both throw errors

Metadata

Metadata

Assignees

No one assigned

    Labels

    has to-upstream testThis bug has a failing to-upstream web platform test waiting to be fixedmetr upliftA candidate for the METR Uplift experimentselectorsCSS Selectors support

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions