feat(security): add tests for style sanitisation.
This commit is contained in:
@ -37,7 +37,12 @@ function hasBalancedQuotes(value: string) {
|
||||
return outsideSingle && outsideDouble;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitizes the given untrusted CSS style property value (i.e. not an entire object, just a single
|
||||
* value) and returns a value that is safe to use in a browser environment.
|
||||
*/
|
||||
export function sanitizeStyle(value: string): string {
|
||||
if (String(value).match(SAFE_STYLE_VALUE) && hasBalancedQuotes(value)) return value;
|
||||
value = String(value); // Make sure it's actually a string.
|
||||
if (value.match(SAFE_STYLE_VALUE) && hasBalancedQuotes(value)) return value;
|
||||
return 'unsafe';
|
||||
}
|
||||
|
Reference in New Issue
Block a user