Repository navigation
Conversation
…them Negative lengths such as `margin-top: -5px`, `top: -10%` or `letter-spacing: -0.5px` were discarded because the length regex had no sign, which also dropped whole shorthands like `margin: -10px 0`. The length regex now accepts an optional sign and requires at least one digit, so `px` and `.px` are no longer parsed as `0` and `NaN`. Size validators reject negative values by default, while the new LongSignedSizeCSSPropertyValidator allows them for margins, offsets (top, right, bottom, left) and letter-spacing. `-0` is normalized to `0`. Refs #59 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The color regex alternation was not grouped, so its first branch was only anchored at the start and its second branch only at the end. Invalid values such as `red !important`, `not a color` or `url(x.png) blue` passed validation and reached React Native styles. Colors are now validated as a whole against: - hex colors with 3, 4, 6 or 8 digits; - rgb(), rgba(), hsl() and hsla() functions, with the same grammar as before; - named colors from css-color-keywords (already a transitive dependency via css-to-react-native), plus `transparent`, `cyan` and `magenta` which React Native supports. Other keywords are discarded, including `inherit` and `currentColor`, which iOS and Android reject. `color` is already inherited by the render engine, so discarding `inherit` gives the expected result. Refs #59 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The `!important` flag was kept as part of the value, so declarations like `margin-top: 5px !important` or `display: flex !important` were discarded, while forgiving properties such as `font-family` kept the flag in their value. The flag is now stripped from every inline declaration, regardless of case and whitespace, and ignored. Between style sources, this makes no difference: inline styles are merged last, and tagsStyles, classesStyles and idsStyles are JS objects which can't carry the flag. Within one style attribute, declarations are still applied in order, so `color: red !important; color: blue` gives blue where a browser shows red, as it did before this change. The CSS concepts documentation page now states that the flag is accepted and ignored in inline styles. Refs #59 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nsitively CSS property names and keywords are ASCII case-insensitive, but uppercase or mixed-case names (`COLOR: red`, `Font-Size: 20px`) failed registry lookup, and uppercase keywords (`display: FLEX`, `margin-top: 5PX`, `color: RED`) were either discarded or passed through to React Native, which rejects them. Names and values are first matched as written, so values which are valid as written are kept unchanged (e.g. `#FFF`) and camelCase property names such as `paddingBottom` keep working. On failure, they get a second attempt lowercased: - property names are lowercased before being camelCased; - validators opt into keyword lowercasing with the new lowercaseInlineCSSKeywords method: enumerations, sizes (units, `auto`, border width and font size keywords), colors and shorthands relying on css-to-react-native (border, background, flex-flow, text-decoration); - hex colors are never lowercased, and the font shorthand only lowercases the part preceding the font family; - font-family, list-style-type and transform values are left untouched, since lowercasing would change what they refer to: font families are matched by exact name against the available fonts, list style types may name user-defined customListStyleSpecs entries, and css-to-react-native expects camelCase transform functions such as `translateX`. This only applies to inline CSS: React Native style values stay case-sensitive. Refs #59 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #61 +/- ##
==========================================
+ Coverage 98.65% 98.69% +0.03%
==========================================
Files 140 141 +1
Lines 2088 2143 +55
Branches 638 648 +10
==========================================
+ Hits 2060 2115 +55
Misses 27 27
Partials 1 1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…x values Two lines were left uncovered: - ShortFontCSSValidator.lowercaseInlineCSSKeywords returns the value unchanged when it has no font size; - ShortMergeRequest.entries with null properties is no longer reached through ShortCSSToReactNativeValidator, which now returns null when css-to-react-native can't expand a value. It is still reached through the flex shorthand. Also reformat a test changed by the case-insensitivity commit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
Fixes #59
Summary
This PR fixes the three bugs from the issue, in one commit each. A fourth commit makes inline CSS ignore
!important. Below: how the validators and the inline parser changed, and which behavior differs from the issue's expected output or frommainbeyond it.Validators
The diff below leaves out intermediate base classes.
lowercaseInlineCSSKeywordsis overridden by validators of sizes, colors, enumerations and css-to-react-native shorthands (border,background,flex-flow,text-decoration,font). They call the newlowercaseCSSKeywordshelper, which leaves hex colors as written.Inline parsing
Design decisions
mainstill gives the same output. camelCase names such aspaddingBottomstill resolve, and a test inrenderrelies on that.#FFFkeeps its case.font-familyis left out because fonts are matched by exact name.list-style-typeis left out because it may name a user-definedcustomListStyleSpecsentry.transformis left out because css-to-react-native expects camelCase function names such astranslateX.fontshorthand, only the part up to the font size is lowercased, so the family keeps its case.fontVariantkeeps the valid items and drops the rest. Insmall-caps OLDSTYLE-NUMS,small-capsis already valid as written, so the second attempt would never run and the second item would be lost.nullon failure. Before, a failed expansion was wrapped in a merge request that merged nothing. ReturningnullletsnormalizePropsee the failure and try again lowercased.splitValueAndUnitrejects negative values unlessallowsNegativeValues()returns true.\w+.css-color-keywordswas already installed throughcss-to-react-native. It is now a direct dependency, with a local type declaration.Behavior changes
maincolor: red !important{ color: 'red !important' }{ color: 'red' }{}. Instead the flag is stripped from every declaration, somargin-top: 5px !importantnow applies too.display: FLEX,border: 1PX SOLID RED{}color: currentColor,color: inherit{}border-color: currentColornow falls back to black.margin-top: px{ marginTop: 0 }{}+5px,.5pxand-0are accepted.tagsStyles: { marginTop: '-5px' }{}{ marginTop: -5 }'px'is now dropped there as well.Unchanged on purpose:
tagsStyles,classesStyles,idsStyles):{ display: 'FLEX' }fails there.{ paddingTop: -5 }is kept.main.!importantwithin onestyleattribute: a later declaration still overrides an earlier important one.color: red !important; color: bluegives blue, where a browser shows red. The docs now say that the flag is accepted and ignored.Evidence
css-processorpassesyarn test(1847 jest tests, tsc and lint) on each of the four commits. New tests cover each row of the table above, and the cases left unchanged on purpose.transient-render-engine(191 tests) andrender(265 tests) pass, and the type check and lint pass fordoc-pages.Merge Danger
Door: Two-way
The changes stay inside
css-processorvalidation code. Validators aren't exported, so no public API changes. Reverting the commits restores the old output.Blast Radius: Styling
maindropped now apply: negative margins and offsets, uppercase names and keywords, and!importantvalues. Existing content can shift.mainpassed through are now dropped: invalid colors,currentColorandinherit.