Permalink
Browse files

Fix multiple classes with regexp

  • Loading branch information...
1 parent 98f0db7 commit e865a17d854b6a957eba7523d9e6ec451cdda2ea @outpunk outpunk committed May 2, 2015
Showing with 8 additions and 11 deletions.
  1. +7 −10 evil-icons.js
  2. +1 −1 test/evil-icons.js
View
@@ -29,18 +29,15 @@ function wrapSpinner(html, klass) {
}
function buildParamsFromString(string) {
- var paramsString;
+ var match, attr, value;
var params = {};
+ var attrsRegexp = /(\S+)=["']?((?:.(?!["']?\s+(?:\S+)=|[>"']))+.)["']?/gi;
- var string = string.trim().replace(/['"]/gi, '');
-
- string.split(' ').forEach(function(param) {
- var param = param.split('=');
- var key = param[0];
- var value = param[1];
-
- params[key] = value;
- });
+ while (match = attrsRegexp.exec(string)) {
+ attr = match[1];
+ value = match[2].replace(/'|"/, '');
+ params[attr] = value;
+ }
return params;
}
View
@@ -88,7 +88,7 @@ describe('Evil Icons', function() {
assert(sprite.length == 1);
- html = icons.iconizeHtml(doc('<body class=red data-attr="a"></body>'));
+ html = icons.iconizeHtml(doc('<body class=red data-attr="a">\n</body>'));
sprite = find(html, '//svg[@id="ei-sprite"]');
assert(sprite.length == 1);

0 comments on commit e865a17

Please sign in to comment.