Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// cssstyle has matured enough that the hacks below are no longer
// necessary, so don't panic.
try {
var cssPropertyParsers = require('cssstyle/lib/parsers');
} catch (err) {
// This error probably just means cssstyle is not installed yet, because
// we're still in the process of upgrading jsdom. Don't worry about it
// until jsdom has been updated to the latest version (v0.8.x).
}
if (cssPropertyParsers) {
// The shorthandParser function should never return a string, but it
// does when given an empty string. Here we detect that case and make it
// return an empty object instead, to work around bugs in later code
// that assume the result of shorthandParser is always an object.
var shorthandParser = cssPropertyParsers.shorthandParser;
cssPropertyParsers.shorthandParser = function() {
var result = shorthandParser.apply(this, arguments);
return result === '' ? {} : result;
};
// Current versions of the cssstyle parseInteger function can't actually
// handle string inputs.
var badInt = cssPropertyParsers.parseInteger('5');
if (badInt !== '5') {
cssPropertyParsers.parseInteger = function parseInteger(val) {
return String(parseInt(val, 10));
};
}
// Current versions of the cssstyle parseNumber function can't actually
// handle string inputs.
// necessary, so don't panic.
try {
var cssPropertyParsers = require('cssstyle/lib/parsers');
} catch (err) {
// This error probably just means cssstyle is not installed yet, because
// we're still in the process of upgrading jsdom. Don't worry about it
// until jsdom has been updated to the latest version (v0.8.x).
}
if (cssPropertyParsers) {
// The shorthandParser function should never return a string, but it
// does when given an empty string. Here we detect that case and make it
// return an empty object instead, to work around bugs in later code
// that assume the result of shorthandParser is always an object.
var shorthandParser = cssPropertyParsers.shorthandParser;
cssPropertyParsers.shorthandParser = function() {
var result = shorthandParser.apply(this, arguments);
return result === '' ? {} : result;
};
// Current versions of the cssstyle parseInteger function can't actually
// handle string inputs.
var badInt = cssPropertyParsers.parseInteger('5');
if (badInt !== '5') {
cssPropertyParsers.parseInteger = function parseInteger(val) {
return String(parseInt(val, 10));
};
}
// Current versions of the cssstyle parseNumber function can't actually
// handle string inputs.
var badNum = cssPropertyParsers.parseNumber('0.5');