Repository navigation
Apply [Clamp] to Blob.slice() and discard Blob types with U+007F - #8793
Conversation
There was a problem hiding this comment.
Superseded by the review of
777c5538.
This review, of 1420906e
✅ Approved — The [Clamp] handling and the U+007F check are correct and covered by the new tests. No issues found.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
📋 Code Quality: ✅ LGTM
relativeOffsethandles NaN, ties-to-even rounding, negative offsets and clamping to [0, size], so thesize_tcast is safe.normalizeType()now rejects bytes outside 0x20–0x7E, which includes U+007F; bytes of 0x80 and above are rejected as before.- The tests cover the new behaviour, and the WPT expectations that the change fixes are removed.
📝 Documentation: ✅ LGTM
The new comment on relativeOffset describes the current behaviour accurately and links to the spec algorithm.
Reviewed commit: 1420906e
The FileAPI spec declares Blob.slice()'s start and end as [Clamp] long long, so fractional values round to the nearest integer with ties to even, NaN becomes 0, and out-of-range values clamp. workerd took them as int, which truncates fractions, turns Infinity into 0 and throws a TypeError outside the int32 range. So `slice(1.5)` started at byte 1 instead of 2, and `slice(0, Infinity)` returned an empty Blob. In this patch slice() takes doubles and converts each one to an offset in the Blob with round-half-to-even, NaN as 0, and a clamp to [0, size] after negative values count back from the end. No call that works today starts throwing: fractional and infinite arguments give the spec's result, and values beyond int32 now clamp instead of throwing. We accept that without a compatibility flag, since the old results ignored the spec's conversion and match no browser. The six Blob-slice WPT expected failures for fractional bounds are removed, and blob-test gets a case for the conversion.
The Blob and File constructors and Blob.slice() set the type to the empty string when it contains a character outside U+0020 to U+007E. normalizeType() only discarded characters below U+0020 and above U+007F, so a type containing U+007F (DEL) was kept. In this patch normalizeType() also discards U+007F. No call starts throwing; such a type now reads back as "" instead of the lowercased string, and we accept that without a compatibility flag because the old value is one the spec and browsers never produce. The U+007F expected failures in the Blob-constructor, Blob-slice and File-constructor WPTs are removed, and blob-test checks the constructor and slice().
1420906 to
777c553
Compare
There was a problem hiding this comment.
✅ Approved — The [Clamp] conversion for slice() bounds and the U+007F check in type normalization are correct and covered by tests; no issues found.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
📋 Code Quality: ✅ LGTM
relativeOffset()handles NaN, ties-to-even rounding, negative offsets and clamping to [0, size], so thesize_tcast is safe.endis raised to at leaststart.normalizeType()rejects bytes outside 0x20–0x7E, which covers U+007F and bytes of 0x80 and above.- The
slicesignature inblob.hmatches the implementation. The tests cover the new behaviour, and the WPT expected failures that this change fixes are removed.
📝 Documentation: ✅ LGTM
The comment on relativeOffset() describes the current behaviour accurately and links to the spec's slice-blob algorithm, as the reviewer asked.
Reviewed commit: 777c5538
The FileAPI spec declares Blob.slice()'s start and end as
[Clamp] long long. workerd took them asint, which truncates fractions, turns Infinity into 0 and throws a TypeError outside the int32 range. Soslice(1.5)started at byte 1 instead of 2, andslice(0, Infinity)returned an empty Blob. The type normalization also kept types containing U+007F, though the spec discards any type with a character outside U+0020 to U+007E.In this patch slice() takes doubles and rounds each bound half to even, with NaN as 0, before the usual negative-offset and clamp steps. normalizeType() also discards U+007F. No call that works today starts throwing: values beyond int32 now clamp instead of throwing, fractional and infinite bounds give the spec's result, and a type containing U+007F reads back as "". We accept these without a compatibility flag, since the old results match no browser.
The six fractional-bound expected failures in Blob-slice and the U+007F ones in Blob-constructor, Blob-slice and File-constructor are removed, and blob-test gets cases for both.
//src/wpt:FileAPI@,//src/wpt:FileAPI@all-autogatesand//src/workerd/api/tests:blob-test@each passed 100 of 100 runs with--runs_per_test=100.