Skip to content

Commit d70b48b

Browse files
authored
fix(css): prevent shorthand parse error on 'unset' and 'inset' (#10424)
1 parent 0847855 commit d70b48b

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"jest-environment-jsdom": "~29.6.0",
5757
"lint-staged": "^14.0.0",
5858
"module-alias": "^2.2.2",
59-
"nativescript": "~8.5.0",
59+
"nativescript": "~8.6.0",
6060
"nativescript-typedoc-theme": "1.1.0",
6161
"nx": "16.9.1",
6262
"parse-css": "git+https://github.com/tabatkins/parse-css.git",

packages/core/ui/styling/css-shadow.spec.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,36 @@ describe('css-shadow', () => {
144144
expect(shadow.spreadRadius).toBeUndefined();
145145
expect(shadow.color).toBeUndefined();
146146
});
147+
148+
it('unset', () => {
149+
const shadow = parseCSSShadow('unset');
150+
expect(shadow.inset).toBe(false);
151+
expect(shadow.offsetX).toBeUndefined();
152+
expect(shadow.offsetY).toBeUndefined();
153+
expect(shadow.blurRadius).toBeUndefined();
154+
expect(shadow.spreadRadius).toBeUndefined();
155+
expect(shadow.color).toBeUndefined();
156+
});
157+
158+
it('unset 5em 1em gold', () => {
159+
// invalid shorthand should result in nothing being applied
160+
const shadow = parseCSSShadow('unset 5em 1em gold');
161+
expect(shadow.inset).toBe(false);
162+
expect(shadow.offsetX).toBeUndefined();
163+
expect(shadow.offsetY).toBeUndefined();
164+
expect(shadow.blurRadius).toBeUndefined();
165+
expect(shadow.spreadRadius).toBeUndefined();
166+
expect(shadow.color).toBeUndefined();
167+
});
168+
169+
it('5em 1em gold unset', () => {
170+
// partially invalid shorthand should result in standard default fallback
171+
const shadow = parseCSSShadow('5em 1em gold unset');
172+
expect(shadow.inset).toBe(false);
173+
expect(shadow.offsetX).toBe(5);
174+
expect(shadow.offsetY).toBe(1);
175+
expect(shadow.blurRadius).toEqual(CoreTypes.zeroLength);
176+
expect(shadow.spreadRadius).toBeUndefined();
177+
expect(shadow.color).toEqual(new Color('black'));
178+
});
147179
});

packages/core/ui/styling/css-utils.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,25 @@ export function parseCSSShorthand(value: string): {
3636
const parts = value.trim().split(PARTS_RE);
3737
const first = parts[0];
3838

39-
if (['', 'none'].includes(first)) {
39+
if (['', 'none', 'unset'].includes(first)) {
4040
return {
4141
inset: false,
4242
color: undefined,
4343
values: [],
4444
};
4545
} else {
46+
const invalidColors = ['inset', 'unset'];
4647
const inset = parts.includes('inset');
4748
const last = parts[parts.length - 1];
4849
let color = 'black';
49-
if (first && !isLength(first) && first !== 'inset') {
50+
if (first && !isLength(first) && !invalidColors.includes(first)) {
5051
color = first;
51-
} else if (last && !isLength(last)) {
52+
} else if (last && !isLength(last) && !invalidColors.includes(last)) {
5253
color = last;
5354
}
5455

5556
const values = parts
56-
.filter((n) => n !== 'inset')
57+
.filter((n) => !invalidColors.includes(n))
5758
.filter((n) => n !== color)
5859
.map((val) => {
5960
try {

0 commit comments

Comments
 (0)