mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 11:01:21 +08:00
fix(css): prevent shorthand parse error on 'unset' and 'inset' (#10424)
This commit is contained in:
@ -56,7 +56,7 @@
|
|||||||
"jest-environment-jsdom": "~29.6.0",
|
"jest-environment-jsdom": "~29.6.0",
|
||||||
"lint-staged": "^14.0.0",
|
"lint-staged": "^14.0.0",
|
||||||
"module-alias": "^2.2.2",
|
"module-alias": "^2.2.2",
|
||||||
"nativescript": "~8.5.0",
|
"nativescript": "~8.6.0",
|
||||||
"nativescript-typedoc-theme": "1.1.0",
|
"nativescript-typedoc-theme": "1.1.0",
|
||||||
"nx": "16.9.1",
|
"nx": "16.9.1",
|
||||||
"parse-css": "git+https://github.com/tabatkins/parse-css.git",
|
"parse-css": "git+https://github.com/tabatkins/parse-css.git",
|
||||||
|
@ -144,4 +144,36 @@ describe('css-shadow', () => {
|
|||||||
expect(shadow.spreadRadius).toBeUndefined();
|
expect(shadow.spreadRadius).toBeUndefined();
|
||||||
expect(shadow.color).toBeUndefined();
|
expect(shadow.color).toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('unset', () => {
|
||||||
|
const shadow = parseCSSShadow('unset');
|
||||||
|
expect(shadow.inset).toBe(false);
|
||||||
|
expect(shadow.offsetX).toBeUndefined();
|
||||||
|
expect(shadow.offsetY).toBeUndefined();
|
||||||
|
expect(shadow.blurRadius).toBeUndefined();
|
||||||
|
expect(shadow.spreadRadius).toBeUndefined();
|
||||||
|
expect(shadow.color).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('unset 5em 1em gold', () => {
|
||||||
|
// invalid shorthand should result in nothing being applied
|
||||||
|
const shadow = parseCSSShadow('unset 5em 1em gold');
|
||||||
|
expect(shadow.inset).toBe(false);
|
||||||
|
expect(shadow.offsetX).toBeUndefined();
|
||||||
|
expect(shadow.offsetY).toBeUndefined();
|
||||||
|
expect(shadow.blurRadius).toBeUndefined();
|
||||||
|
expect(shadow.spreadRadius).toBeUndefined();
|
||||||
|
expect(shadow.color).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('5em 1em gold unset', () => {
|
||||||
|
// partially invalid shorthand should result in standard default fallback
|
||||||
|
const shadow = parseCSSShadow('5em 1em gold unset');
|
||||||
|
expect(shadow.inset).toBe(false);
|
||||||
|
expect(shadow.offsetX).toBe(5);
|
||||||
|
expect(shadow.offsetY).toBe(1);
|
||||||
|
expect(shadow.blurRadius).toEqual(CoreTypes.zeroLength);
|
||||||
|
expect(shadow.spreadRadius).toBeUndefined();
|
||||||
|
expect(shadow.color).toEqual(new Color('black'));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -36,24 +36,25 @@ export function parseCSSShorthand(value: string): {
|
|||||||
const parts = value.trim().split(PARTS_RE);
|
const parts = value.trim().split(PARTS_RE);
|
||||||
const first = parts[0];
|
const first = parts[0];
|
||||||
|
|
||||||
if (['', 'none'].includes(first)) {
|
if (['', 'none', 'unset'].includes(first)) {
|
||||||
return {
|
return {
|
||||||
inset: false,
|
inset: false,
|
||||||
color: undefined,
|
color: undefined,
|
||||||
values: [],
|
values: [],
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
|
const invalidColors = ['inset', 'unset'];
|
||||||
const inset = parts.includes('inset');
|
const inset = parts.includes('inset');
|
||||||
const last = parts[parts.length - 1];
|
const last = parts[parts.length - 1];
|
||||||
let color = 'black';
|
let color = 'black';
|
||||||
if (first && !isLength(first) && first !== 'inset') {
|
if (first && !isLength(first) && !invalidColors.includes(first)) {
|
||||||
color = first;
|
color = first;
|
||||||
} else if (last && !isLength(last)) {
|
} else if (last && !isLength(last) && !invalidColors.includes(last)) {
|
||||||
color = last;
|
color = last;
|
||||||
}
|
}
|
||||||
|
|
||||||
const values = parts
|
const values = parts
|
||||||
.filter((n) => n !== 'inset')
|
.filter((n) => !invalidColors.includes(n))
|
||||||
.filter((n) => n !== color)
|
.filter((n) => n !== color)
|
||||||
.map((val) => {
|
.map((val) => {
|
||||||
try {
|
try {
|
||||||
|
Reference in New Issue
Block a user