Reject negative lengths for border-spacing - #321
Closed
afonsojanu wants to merge 1 commit into
Closed
Conversation
The CSS Tables spec defines border-spacing as <length [0,∞]>{1,2} and
says the values "must be non-negative". Every sibling length property
in this codebase that has the same constraint (border-width, padding,
width, height, line-height, flex-grow/shrink) passes min: 0 into
resolveNumericValue, but borderSpacing.js never did, so a negative
length was happily accepted and stored:
style.borderSpacing = '-10px';
style.borderSpacing; // '-10px', should be rejected
This adds the missing min: 0 to both the single-value and two-value
branches of the parser, matching how the rest of the codebase handles
non-negative lengths, and adds three tests covering a single negative
value and a negative value in either position of a two-value pair.
Co-authored-by: Claude <noreply@anthropic.com>
Member
|
This project is no longer maintained; it has been rolled into jsdom. Good reminder to archive it though. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
border-spacingcurrently accepts and stores negative lengths, e.g.:That's not spec-compliant. The CSS Tables spec defines the property as
<length [0,∞]>{1,2}and its prose says the values "must be non-negative" (this carries over from CSS 2.1, which put it even more plainly: "Negative values for<length>are illegal").Looking through the other length properties in this codebase that carry the same non-negative constraint, they all pass
min: 0intoresolveNumericValue/serializeLength:border-*-width,padding*,width,height,line-height,flex-grow/flex-shrink.border-spacingis the one property with that same constraint that was missing it, in both the single-value and two-value branches of its parser.Fix
Adds
min: 0to theresolveNumericValuecalls inlib/properties/borderSpacing.js, for both the one-length and two-length forms. With this in place, a negative length now falls through toundefinedthe same way it already does for the sibling properties, and the whole property is left unset (matching how e.g.border-top-width: -1pxalready behaves here).Test plan
test/properties.test.js: a single negative length, a negative length as the first of two values, and as the second of two values. All assert the property does not get set.'-10px' !== '', etc.) and pass with the fix.node --testpasses (664/664).eslintis clean on both changed files.Disclosure
I used an AI coding assistant (Claude) to help investigate and write this fix, per this project's contribution norms.