Permalink
Browse files

Fixed attribute issue with over greedy regexp

  • Loading branch information...
1 parent b6f8a75 commit 87d03304b864611576af105f2073df4a39be22b3 @tj tj committed Oct 30, 2010
Showing with 32 additions and 4 deletions.
  1. +32 −4 lib/lexer.js
View
@@ -97,6 +97,33 @@ Lexer.prototype = {
},
/**
+ * Return the indexOf `start` / `end` delimiters.
+ *
+ * @param {String} start
+ * @param {String} end
+ * @return {Number}
+ * @api private
+ */
+
+ indexOfDelimiters: function(start, end){
+ var str = this.input,
+ nstart = 0,
+ nend = 0,
+ pos = 0;
+ for (var i = 0, len = str.length; i < len; ++i) {
+ if (start == str[i]) {
+ ++nstart;
+ } else if (end == str[i]) {
+ if (++nend == nstart) {
+ pos = i;
+ break;
+ }
+ }
+ }
+ return pos;
+ },
+
+ /**
* Stashed token.
*/
@@ -224,10 +251,11 @@ Lexer.prototype = {
*/
get attrs() {
- var captures;
- if (captures = /^\((.+)\)/.exec(this.input)) {
- this.consume(captures[0].length);
- var tok = this.tok('attrs', captures[1]),
+ if ('(' == this.input[0]) {
+ var index = this.indexOfDelimiters('(', ')'),
+ str = this.input.substr(1, index-1);
+ this.consume(index + 1);
+ var tok = this.tok('attrs', str),
attrs = tok.val.split(/ *, *(?=['"\w-]+ *[:=]|[\w-]+ *$)/);
tok.attrs = {};
for (var i = 0, len = attrs.length; i < len; ++i) {

0 comments on commit 87d0330

Please sign in to comment.