You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Native tsc reads a literal U+FFFD in a regex character class as 0xEF (false TS1517 / TS1516) #65076
repro.ts ends up as this. The last character in the class is a literal U+FFFD (bytes EF BF BD):
exportconstr=/[\uFFF9-�]/
🙁 Actual behavior
repro.ts(1,20): error TS1517: Range out of order in character class.
U+FFF9 to U+FFFD is in order, so the range is fine. With the u flag the same class gets a different wrong error:
error TS1516: A character class range must not be bounded by another character class.
🙂 Expected behavior
No error, same as 6.0.3. The regex is valid at runtime and matches U+FFF9 through U+FFFD.
Additional information about the issue
It looks like a literal U+FFFD gets read as 0xEF, the first byte of its UTF-8 encoding. Changing only the start of the range:
Character class
6.0.3
7.0.2 and 7.1.0-dev.20261031.1
[\u00EF-�]
ok
ok
[\u00F0-�]
ok
TS1517
[\u0100-�]
ok
TS1517
[\uFFF9-�]
ok
TS1517
[\uFFF9-\uFFFD] (escaped)
ok
ok
A lone literal U+FFFD (/�/) and one that starts a range (/[�-\uFFFF]/) are both fine on all three versions, and so is a string literal: const s: "\uFFFD" = "�" type-checks. So it seems specific to the regex scanner.
My guess, without having read the code: Go's utf8.RuneError is U+FFFD, so a check like r == utf8.RuneError treats a real U+FFFD as invalid UTF-8 unless it also looks at the size (3 bytes for a real U+FFFD, 1 for bad input).
I ran into this in a test that checks some text has no characters in that block, and worked around it with the escaped form.
Activity