Fixes #305 - allows width keywords in border-width.
authorEric Anderson <eric@pixelwareinc.com>
Fri, 27 Jun 2014 22:19:20 +0000 (18:19 -0400)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Sun, 29 Jun 2014 12:11:40 +0000 (13:11 +0100)
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.

History.md
lib/properties/validator.js
test/data/issue-305-min.css [new file with mode: 0644]
test/data/issue-305.css [new file with mode: 0644]

index 379eca3..4ccd277 100644 (file)
@@ -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)
 ==================
 
index acfed8b..0fa2a8c 100644 (file)
@@ -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 (file)
index 0000000..dd25f0f
--- /dev/null
@@ -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 (file)
index 0000000..2cced35
--- /dev/null
@@ -0,0 +1,3 @@
+div {
+  border-width: thin;
+}