Permalink
Browse files

to_short_hex() critical fix

  • Loading branch information...
1 parent 959dba7 commit e90de7b4a8f3a32537e75f2081644df8d1602f31 @monolithed committed May 19, 2012
Showing with 15 additions and 5 deletions.
  1. +15 −5 JavaScript version/toCSS.js
@@ -103,12 +103,22 @@ var toCSS = new function() {
* @return: {String}
*/
to_short_hex: function(text) {
- return text.replace(/#([\da-fA-F]{6})\b/g, function() {
- return '#' + RegExp.$1.split('').filter(function(element, i) {
- return i % 2 == i++ % 2 && i % 2;
+ var match = text.match(/#([\da-fA-F]{6})\b/);
+
+ if (!match)
+ return text;
+
+ var slice = function(diff) {
+ var hex = match[1];
+
+ return '#' + hex.split('').filter(function(element, index) {
+ if ((diff ? ++index : index) % 2)
+ return hex[index];
}).join('');
- });
- },
+ };
+
+ return slice(1) === slice(0) ? slice(1) : text;
+ },
/*!
* Convert RGB notation into a HEX triplet

0 comments on commit e90de7b

Please sign in to comment.