From: Eric Anderson Date: Fri, 27 Jun 2014 22:19:20 +0000 (-0400) Subject: Fixes #305 - allows width keywords in border-width. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=b9eb5c17c9b60b09c37a6078b95ca4d84dba6d25;p=clean-css.git Fixes #305 - allows width keywords in border-width. When not all sides are specified for things like border/padding/margin it appears clean-css attempts to normalize the data (i.e "2px 5px" -> "2px 5px 2px 5px"). This normalization appears to only look for things matched to cssUnitAnyRegexStr. cssUnitAnyRegexStr doesn't include width keywords. The width keywords were already specified for validating outline width. This commit renames that list to be more generic (just widthKeywords). It then adds this list to the cssUnitAnyRegexStr regexp. This commit fixes #305. In addition I added "initial" to the list of width keywords to fix gruntjs/grunt-contrib-cssmin#103 which is the issue that lead me to writing this patch. So this commit should solve that as well. --- diff --git a/History.md b/History.md index 379eca34..4ccd2770 100644 --- a/History.md +++ b/History.md @@ -1,3 +1,8 @@ +[2.2.5 / 2014-xx-xx](https://github.com/GoalSmashers/clean-css/compare/v2.2.4...v2.2.5) +================== + +* Fixed issue [#305](https://github.com/GoalSmashers/clean-css/issues/305) - allows width keywords in border-width. + [2.2.4 / 2014-06-27](https://github.com/GoalSmashers/clean-css/compare/v2.2.3...v2.2.4) ================== diff --git a/lib/properties/validator.js b/lib/properties/validator.js index acfed8b9..0fa2a8c5 100644 --- a/lib/properties/validator.js +++ b/lib/properties/validator.js @@ -3,11 +3,12 @@ module.exports = (function () { // Regexes used for stuff + var widthKeywords = ['thin', 'thick', 'medium', 'inherit', 'initial']; var cssUnitRegexStr = '(\\-?\\.?\\d+\\.?\\d*(px|%|em|rem|in|cm|mm|ex|pt|pc|vw|vh|vmin|vmax|)|auto|inherit)'; var cssFunctionNoVendorRegexStr = '[A-Z]+(\\-|[A-Z]|[0-9])+\\(([A-Z]|[0-9]|\\ |\\,|\\#|\\+|\\-|\\%|\\.)*\\)'; var cssFunctionVendorRegexStr = '\\-(\\-|[A-Z]|[0-9])+\\(([A-Z]|[0-9]|\\ |\\,|\\#|\\+|\\-|\\%|\\.)*\\)'; var cssFunctionAnyRegexStr = '(' + cssFunctionNoVendorRegexStr + '|' + cssFunctionVendorRegexStr + ')'; - var cssUnitAnyRegexStr = '(none|' + cssUnitRegexStr + '|' + cssFunctionNoVendorRegexStr + '|' + cssFunctionVendorRegexStr + ')'; + var cssUnitAnyRegexStr = '(none|' + widthKeywords.join('|') + '|' + cssUnitRegexStr + '|' + cssFunctionNoVendorRegexStr + '|' + cssFunctionVendorRegexStr + ')'; var backgroundRepeatKeywords = ['repeat', 'no-repeat', 'repeat-x', 'repeat-y', 'inherit']; var backgroundAttachmentKeywords = ['inherit', 'scroll', 'fixed', 'local']; @@ -15,7 +16,6 @@ module.exports = (function () { var listStyleTypeKeywords = ['armenian', 'circle', 'cjk-ideographic', 'decimal', 'decimal-leading-zero', 'disc', 'georgian', 'hebrew', 'hiragana', 'hiragana-iroha', 'inherit', 'katakana', 'katakana-iroha', 'lower-alpha', 'lower-greek', 'lower-latin', 'lower-roman', 'none', 'square', 'upper-alpha', 'upper-latin', 'upper-roman']; var listStylePositionKeywords = ['inside', 'outside', 'inherit']; var outlineStyleKeywords = ['auto', 'inherit', 'hidden', 'none', 'dotted', 'dashed', 'solid', 'double', 'groove', 'ridge', 'inset', 'outset']; - var outlineWidthKeywords = ['thin', 'thick', 'medium', 'inherit']; var validator = { isValidHexColor: function (s) { @@ -90,7 +90,7 @@ module.exports = (function () { return outlineStyleKeywords.indexOf(s) >= 0; }, isValidOutlineWidth: function (s) { - return validator.isValidUnit(s) || outlineWidthKeywords.indexOf(s) >= 0; + return validator.isValidUnit(s) || widthKeywords.indexOf(s) >= 0; }, isValidVendorPrefixedValue: function (s) { return /^-([A-Za-z0-9]|-)*$/gi.test(s); diff --git a/test/data/issue-305-min.css b/test/data/issue-305-min.css new file mode 100644 index 00000000..dd25f0ff --- /dev/null +++ b/test/data/issue-305-min.css @@ -0,0 +1 @@ +div{border-width:thin} diff --git a/test/data/issue-305.css b/test/data/issue-305.css new file mode 100644 index 00000000..2cced350 --- /dev/null +++ b/test/data/issue-305.css @@ -0,0 +1,3 @@ +div { + border-width: thin; +}