Skip to content

Commit

Permalink
Filter invalid styles from CSSStyleDeclaration (#238)
Browse files Browse the repository at this point in the history
* Filter invalid styles from CSSStyleDeclaration

* Move filtering of numeric keys to appendKeys, and test
  • Loading branch information
kristoferbaxter authored Jan 23, 2019
1 parent 292c70f commit d7969c8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/test/cssstyledeclaration/appendKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ test.serial('previously appended keys should exist on newly declared instances',
t.is(declaration.width, '');
});

test('invalid keys are filtered', t => {
const initialLength = CSSStyleDeclaration.prototype.length;

appendKeys(['0']);
t.is(CSSStyleDeclaration.prototype.length, initialLength);
});

test('appending keys mutates all known declaration instances', t => {
const firstDeclaration = new CSSStyleDeclaration(t.context.node);
const secondDeclaration = new CSSStyleDeclaration(t.context.node);
Expand Down
2 changes: 1 addition & 1 deletion src/worker-thread/css/CSSStyleDeclaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ interface StyleDeclaration {
const hyphenateKey = (key: string): string => toLower(key.replace(/(webkit|ms|moz|khtml)/g, '-$1').replace(/([a-zA-Z])(?=[A-Z])/g, '$1-'));

export const appendKeys = (keys: Array<string>): void => {
const keysToAppend = keys.filter(key => !CSSStyleDeclaration.prototype.hasOwnProperty(key));
const keysToAppend = keys.filter(key => isNaN(key as any) && !CSSStyleDeclaration.prototype.hasOwnProperty(key));
if (keysToAppend.length <= 0) {
return;
}
Expand Down

0 comments on commit d7969c8

Please sign in to comment.