Using a hyphen causes bad data selector syntax

1 view
Skip to first unread message

Jeff

unread,
Aug 19, 2009, 6:47:08 AM8/19/09
to PURE - JavaScript Templates Engine
Hello,
I'm using PURE2 and I'm getting a "bad data selector syntax:
forum.topic-count" error while trying to render this JSON object:

{"forums": [{"title":"General Discussion","topic-count":20,"post-
count":59},
{"title":"Product Questions","topic-count":20,"post-
count":59},
{"title":"Customer Support","topic-count":20,"post-
count":59}]}

using this directive:

var directive = {
'.forum-entry': {
'forum <- forums': {
'.title': 'forum.title',
'.topic-count': 'forum.topic-count',
'.post-count': 'forum.post-count'
}
}
};

$(".forum-list").autoRender(forums, directive)

It renders correctly if I remove the hyphens from the names, so I
narrowed down the problem to this regular expression on line 197 of
pure2.js:

var m = sel.match(/^(\w+)(\.(\w+))*$/);

While hyphens aren't valid javascript syntax, I don't see why it would
be necessary to require them for JSON object lookups, since a context
['foo-bar'] type of lookup will work fine. Many JSON objects coming
from various rest services could use hyphens, so how about changing
this regexp and making pure a bit more open to arbitrary data selector
keys?

Besides this hangup, PURE is really nice to use. Thanks for the great
stuff.

-Jeff

Mic Cvilic

unread,
Aug 19, 2009, 3:19:32 PM8/19/09
to Pure-Unobtrusive...@googlegroups.com
Jeff wrote:
> Hello,
> I'm using PURE2 and I'm getting a "bad data selector syntax:
> forum.topic-count" error while trying to render this JSON object:
>
> {"forums": [{"title":"General Discussion","topic-count":20,"post-
> count":59},
> {"title":"Product Questions","topic-count":20,"post-
> count":59},
> {"title":"Customer Support","topic-count":20,"post-
> count":59}]}
>
> using this directive:
>
> var directive = {
> '.forum-entry': {
> 'forum <- forums': {
> '.title': 'forum.title',
> '.topic-count': 'forum.topic-count',
> '.post-count': 'forum.post-count'
> }
> }
> };
>
> $(".forum-list").autoRender(forums, directive)
>
> It renders correctly if I remove the hyphens from the names, so I
> narrowed down the problem to this regular expression on line 197 of
> pure2.js:
>
> var m = sel.match(/^(\w+)(\.(\w+))*$/);
>
Now I know that hyphen is not part of \w ;)
You're right the regexp is too restrictive and should allow it.
I've set an issue at http://github.com/pure/pure/issues/#issue/7
You'll be able to follow the progress there.

Thanks for reporting.
Mic
Reply all
Reply to author
Forward
0 new messages