Repository navigation
fix(codemode): honor localeCompare locales and collator options - #64935
Conversation
There was a problem hiding this comment.
I found nothing that should block this. On the base, the numeric sort returned a1, a10, a9, sensitivity: "base" and ignorePunctuation returned -1, and invalid locales or options were silently accepted. With this change the results match the host collator (a1, a9, a10, 0, 0), and bad tags, option values and null throw catchable RangeError/TypeErrors.
Beyond your cases, I checked that getter and toString options are read in collator order, that array-like locale lists and huge lengths are handled, and that host namespaces passed as a locale or option go through the host's normal conversion and expose nothing. The parity and string test262 tests pass, the full packages/codemode suite passes (1787 tests), and tsc --noEmit passes.
The public API is unchanged: this is internal to the Code Mode language stdlib.
|
Security follow-up: locale lists over 100 entries (arrays and array-likes, checked before any element is read) and tags over 256 characters now throw a catchable |
There was a problem hiding this comment.
The new commits look sound and I found nothing that blocks a merge.
The locale list is now capped at 100 entries, checked before any element is read, and each tag at 256 characters, checked after objects in the list are converted to strings. Both limits live with the other interpreter limits in limits.ts.
The parity and string test262 tests pass, the full packages/codemode suite passes (1788 tests), and tsc --noEmit passes. I re-ran my earlier checks and the collator behaviour is unchanged. The new test checks the boundary on each side of both caps and that a too-long list is rejected without reading any element.
The public API is unchanged: this is internal to the Code Mode language runtime and stdlib.
This reverts commit cc02677.
|
Removed the size caps from this PR at the maintainer's request. |
There was a problem hiding this comment.
The new commit is a clean revert of the locale-cap commit, and I see no problem with it. The code is now the same as the version I first reviewed, which I had already verified.
Without the cap, a locale list is limited only by the interpreter's array-length limit and tags have no length cap. I timed both at this head: 100,000 locale tags took about 0.3 s and a 160,000-character tag about 0.1 s, so dropping the cap doesn't look risky.
The parity and string test262 tests pass (306) and tsc --noEmit passes. The public API is unchanged.
Summary
String.prototype.localeComparein Code Mode ignored itslocalesandoptionsarguments, so natural sorting and case-insensitive comparison quietly gave the wrong answer. It now hands the program's locales and collator options to the host'slocaleCompare, so results match Bun. Getters andtoStringobjects in the options are read and converted first. With no locales or options, it runs the same call as before. No globalIntlis added.a1, a9, a10a1, a10, a9a1, a9, a10a/A)0-10a/á)0-100-10Invalid locale tags and option values throw catchable
RangeErrors, and a non-string locale throws aTypeError, as in Bun.nulllocales or options throw a clearTypeErrorinstead of the host's message, which would show the runtime's own source.Testing
bun test test/parity.test.ts test/string-core-test262.test.ts(new parity tests check numeric, sensitivity, caseFirst, ignorePunctuation, a getter option, atoStringoption, a locale array, thesvlocale, and the error cases; expected values were checked againstbun -e)bun typecheckinpackages/codemode;bun run checkat the rootpackages/codemodesuite: 1787 pass, 0 fail.Visual