var WHOLE_PIXEL_VALUE = /(?:^|\s|\()(-?\d+)px/;
var TIME_VALUE = /^(\-?[\d\.]+)(m?s)$/;
+var PROPERTY_NAME_PATTERN = /^(?:\-chrome\-|\-[\w\-]+\w|\w[\w\-]+\w|\-\-\S+)$/;
var IMPORT_PREFIX_PATTERN = /^@import/i;
var QUOTED_PATTERN = /^('.*'|".*")$/;
var QUOTED_BUT_SAFE_PATTERN = /^['"][a-zA-Z][a-zA-Z\d\-_]+['"]$/;
property = _properties[i];
name = property.name;
+ if (!PROPERTY_NAME_PATTERN.test(name)) {
+ propertyToken = property.all[property.position];
+ context.warnings.push('Invalid property name \'' + name + '\' at ' + formatPosition(propertyToken[1][2][0]) + '. Ignoring.');
+ property.unused = true;
+ }
+
if (property.value.length === 0) {
propertyToken = property.all[property.position];
context.warnings.push('Empty property \'' + name + '\' at ' + formatPosition(propertyToken[1][2][0]) + '. Ignoring.');
assert.equal(minified.warnings[1], 'Invalid selector \'color:#535353}p\' at 1:16. Ignoring.');
}
},
+ 'warning on invalid property': {
+ 'topic': function () {
+ return new CleanCSS().minify('a{-webkit-:0px}');
+ },
+ 'should minify correctly': function (error, minified) {
+ assert.isEmpty(minified.styles);
+ },
+ 'should raise no errors': function (error, minified) {
+ assert.isEmpty(minified.errors);
+ },
+ 'should raise one warning': function (error, minified) {
+ assert.lengthOf(minified.warnings, 1);
+ assert.equal(minified.warnings[0], 'Invalid property name \'-webkit-\' at 1:2. Ignoring.');
+ }
+ },
'warnings on empty properties': {
'topic': function () {
return new CleanCSS().minify('a{color:}');
]
}, { advanced: false, compatibility: { properties: { shorterLengthUnits: true }, units: { in: false, pt: false } } })
)
+ .addBatch(
+ optimizerContext('property name validation', {
+ 'trimmed': [
+ 'a{-webkit-:0 0 2px red}',
+ ''
+ ],
+ 'with incorrect characters': [
+ 'a{color+other:red}',
+ ''
+ ],
+ 'for chrome only': [
+ 'a{-chrome-:only(;color:red;)}',
+ 'a{-chrome-:only(;color:red;)}'
+ ],
+ 'custom vendor prefix': [
+ 'a{-custom-color:red}',
+ 'a{-custom-color:red}'
+ ]
+ }, { advanced: false })
+ )
.export(module);