Invalid selector generated when id is numeric

An invalid selector is generated when the element (or a parent) starts with a number.

Reduced test-case

<div id="123"><li></li></div>

Expected result

A valid selector, probably easiest with [id="123"] but possibly with CSS escapes.

Actual result

An invalid selector is generated:

"selector": "#123 > li"

Trying to run this selector with document.querySelector("#123") (correctly) yields the error:

Uncaught DOMException: Failed to execute 'querySelector' on 'Document': '#123' is not a valid selector. at :1:10