Skip to content

Commit

Permalink
Fix for #198, with regexen, and urlencoding if the token is uppercase.
Browse files Browse the repository at this point in the history
  • Loading branch information
dbergey authored and Alexis Sellier committed May 3, 2011
1 parent 0202b29 commit d7cdc17
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/less/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,10 @@ tree.functions = {
str = quoted.value;

for (var i = 0; i < args.length; i++) {
str = str.replace(/%s/, args[i].value)
.replace(/%[da]/, args[i].toCSS());
str = str.replace(/%[sda]/i, function(token) {
var value = token.match(/s/i) ? args[i].value : args[i].toCSS();
return token.match(/[A-Z]$/) ? encodeURIComponent(value) : value;
});
}
str = str.replace(/%%/g, '%');
return new(tree.Quoted)('"' + str + '"', str);
Expand Down
2 changes: 2 additions & 0 deletions test/css/functions.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
spin-n: #bf4055;
format: "rgb(32, 128, 64)";
format-string: "hello world";
format-multiple: "hello earth 2";
format-url-encode: "red is %23ff0000";
eformat: rgb(32, 128, 64);
hue: 98;
saturation: 12%;
Expand Down
2 changes: 2 additions & 0 deletions test/less/functions.less
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
spin-n: spin(hsl(30, 50%, 50%), -40);
format: %("rgb(%d, %d, %d)", @r, 128, 64);
format-string: %("hello %s", "world");
format-multiple: %("hello %s %d", "earth", 2);
format-url-encode: %('red is %A', #ff0000);
eformat: e(%("rgb(%d, %d, %d)", @r, 128, 64));

hue: hue(hsl(98, 12%, 95%));
Expand Down

0 comments on commit d7cdc17

Please sign in to comment.