Discussion:
Issue 55 in json-template: Section names not looked up properly
j***@public.gmane.org
2010-03-05 06:44:50 UTC
Permalink
Status: New
Owner: ----
Labels: Type-Defect Priority-Medium

New issue 55 by micah.stetson: Section names not looked up properly
http://code.google.com/p/json-template/issues/detail?id=55

Given this data: {"a":{"b":{"c":1}},"d":2}
Try processing Template 1:

{.section a.b}{c}{.end}

Or Template 2:

{.section a}{.section d}{@}{.end}{.end}

I expect template 1 to output "1" and template 2 to output "2". Instead,
template 1 yields "EXCEPTION: UndefinedVariable: c is not defined", and
template 2 yields "null".

I'm using sroussey's PHP version of JSON Template pulled this evening from
his repo here:

https://sroussey-json-template.googlecode.com/hg/

But I think the problem affects more than the PHP version, it's at least
present in the python version as well.

This diff against sroussey-json-template fixes the PHP version:

diff -r b9d923fb113e php/jsontemplate.php
--- a/php/jsontemplate.php Mon Oct 12 23:49:51 2009 -0700
+++ b/php/jsontemplate.php Thu Mar 04 22:20:02 2010 -0800
@@ -372,24 +372,10 @@

function PushSection($name)
{
- $end = end($this->stack);
- $new_context=null;
- if(is_array($end)){
- if(isset($end[$name])){
- $new_context = $end[$name];
- }
- }elseif(is_object($end)){
- // since json_decode returns StdClass
- // check if scope is an object
- if(property_exists($end,$name)){
- $new_context = $end->$name;
- } else if (method_exists($end,$getter="get$name")){
- $new_context = $end->$getter();
- } else if (method_exists($end,'__get')){
- try {
- $new_context = $end->$name;
- } catch (exception $e){}
- }
+ try {
+ $new_context = $this->Lookup($name);
+ } catch(JsonTemplateUndefinedVariable $e) {
+ $new_context = null;
}
$this->name_stack[] = $name;
$this->stack[] = $new_context;
@@ -653,7 +639,7 @@
class JsonTemplateModule
{

- public $section_re = '/^(?:(repeated)\s+)?(section)\s+(@|[A-Za-z0-
9_-]+)(?:\b(.*))?$/';
+ public $section_re = '/^(?:(repeated)\s+)?(section)\s+(@|[A-Za-z0-
9_-]+(\.[A-Za-z0-9_-]+)*)(?:\b(.*))?$/';
public $if_re = '/^if\s+(@|[A-Za-z0-9_-]+)(\?)?(?:\b(.*?))?\s*$/';
public $option_re = '/^([a-zA-Z\-]+):\s*(.*)/';
public $option_names = array('meta','format-char','default-formatter');


--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:
http://code.google.com/hosting/settings
--
You received this message because you are subscribed to the Google Groups "JSON Template" group.
To post to this group, send email to json-template-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To unsubscribe from this group, send email to json-template+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit this group at http://groups.google.com/group/json-template?hl=en.
j***@public.gmane.org
2010-03-05 20:40:47 UTC
Permalink
Updates:
Owner: sroussey

Comment #1 on issue 55 by sroussey: Section names not looked up properly
http://code.google.com/p/json-template/issues/detail?id=55

I haven't contributed back the changes I've made recently. I think a fix
for this is
one of them (and it is elsewhere in the code). I'll get on this next week.

--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:
http://code.google.com/hosting/settings
--
You received this message because you are subscribed to the Google Groups "JSON Template" group.
To post to this group, send email to json-template-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To unsubscribe from this group, send email to json-template+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit this group at http://groups.google.com/group/json-template?hl=en.
peg
2010-03-23 11:51:06 UTC
Permalink
hi all,

Similar problem with javascript ?

datas = '{ "items":[ { "name": "item1" }, { "name": "item2" } ],
"show": "true" }'

template = "{.section items}{.section show} SHOW {.or} DON'T SHOW
{.end}{.or} NO ITEMS {.end}"

result = "DON'T SHOW"

thanks
        Owner: sroussey
Comment #1 on issue 55 by sroussey: Section names not looked up properlyhttp://code.google.com/p/json-template/issues/detail?id=55
I haven't contributed back the changes I've made recently. I think a fix  
for this is
one of them (and it is elsewhere in the code). I'll get on this next week.
--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:http://code.google.com/hosting/settings
--
You received this message because you are subscribed to the Google Groups "JSON Template" group.
To post to this group, send email to json-template-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To unsubscribe from this group, send email to json-template+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/json-template?hl=en.
Miles
2010-03-25 02:48:55 UTC
Permalink
Post by peg
hi all,
Similar problem with javascript ?
datas =  '{ "items":[ { "name": "item1" },  { "name": "item2" } ],
"show": "true" }'
template  = "{.section items}{.section show} SHOW {.or} DON'T SHOW
{.end}{.or} NO ITEMS {.end}"
result = "DON'T SHOW"
thanks
We have similar problem - even with single section - if the section is
not null, nothing appears, if it is null, it correctly executes
{.or}

it's a serious bug - tried to look at source but couldn't see fix
right away - we really need a fix or workaround so would appreciate
any help. thks.
Post by peg
        Owner: sroussey
Comment #1 on issue 55 by sroussey: Section names not looked up properlyhttp://code.google.com/p/json-template/issues/detail?id=55
I haven't contributed back the changes I've made recently. I think a fix  
for this is
one of them (and it is elsewhere in the code). I'll get on this next week.
--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:http://code.google.com/hosting/settings
--
You received this message because you are subscribed to the Google Groups "JSON Template" group.
To post to this group, send email to json-template-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To unsubscribe from this group, send email to json-template+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/json-template?hl=en.
Steven Roussey
2010-03-25 04:03:52 UTC
Permalink
OK, I'm looking at this tonight and tomorrow night. So please, if you
can, provide a test case, and which version (JS/PHP, etc) and I'll
make sure it passes.
Post by Miles
Post by peg
hi all,
Similar problem with javascript ?
datas =  '{ "items":[ { "name": "item1" },  { "name": "item2" } ],
"show": "true" }'
template  = "{.section items}{.section show} SHOW {.or} DON'T SHOW
{.end}{.or} NO ITEMS {.end}"
result = "DON'T SHOW"
thanks
We have similar problem - even with single section - if the section is
not null, nothing appears, if it is null, it correctly executes
{.or}
it's a serious bug - tried to look at source but couldn't see fix
right away - we really need a fix or workaround so would appreciate
any help.   thks.
Post by peg
        Owner: sroussey
Comment #1 on issue 55 by sroussey: Section names not looked up properlyhttp://code.google.com/p/json-template/issues/detail?id=55
I haven't contributed back the changes I've made recently. I think a fix  
for this is
one of them (and it is elsewhere in the code). I'll get on this next week.
--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:http://code.google.com/hosting/settings
--
You received this message because you are subscribed to the Google Groups "JSON Template" group.
To post to this group, send email to json-template-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To unsubscribe from this group, send email to json-template+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/json-template?hl=en.
Steven Roussey
2010-03-26 02:58:32 UTC
Permalink
My JS version (that I use) has diverged quite a bit over time, and I
am not very motivated to try and merge back. When I run this:

data= { "items":[ { "name": "item1" }, { "name": "item2" } ], "show":
"true" };
template = "{.section items}{.section show} SHOW {.or} DON'T SHOW
{.end}{.or} NO ITEMS {.end}"
t=jsontemplate.Template(template)
t.expand(data)

I get the result:

" SHOW "

Which json-template.js are you using?

-steve--
Post by Miles
Post by peg
hi all,
Similar problem with javascript ?
datas =  '{ "items":[ { "name": "item1" },  { "name": "item2" } ],
"show": "true" }'
template  = "{.section items}{.section show} SHOW {.or} DON'T SHOW
{.end}{.or} NO ITEMS {.end}"
result = "DON'T SHOW"
thanks
We have similar problem - even with single section - if the section is
not null, nothing appears, if it is null, it correctly executes
{.or}
it's a serious bug - tried to look at source but couldn't see fix
right away - we really need a fix or workaround so would appreciate
any help.   thks.
Post by peg
        Owner: sroussey
Comment #1 on issue 55 by sroussey: Section names not looked up properlyhttp://code.google.com/p/json-template/issues/detail?id=55
I haven't contributed back the changes I've made recently. I think a fix  
for this is
one of them (and it is elsewhere in the code). I'll get on this next week.
--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:http://code.google.com/hosting/settings
--
You received this message because you are subscribed to the Google Groups "JSON Template" group.
To post to this group, send email to json-template-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To unsubscribe from this group, send email to json-template+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/json-template?hl=en.
MilesTogoe
2010-03-26 17:12:48 UTC
Permalink
Post by Steven Roussey
My JS version (that I use) has diverged quite a bit over time, and I
"true" };
template = "{.section items}{.section show} SHOW {.or} DON'T SHOW
{.end}{.or} NO ITEMS {.end}"
t=jsontemplate.Template(template)
t.expand(data)
" SHOW "
Which json-template.js are you using?
We're running:
Fedora 12
node v0.1.32-4
node-router

json-template - we don't see a version listed anywhere ! not in docs,
not in source ! we did download it about 2 wks ago but don't see our
original clone download date
Post by Steven Roussey
-steve--
Post by Miles
Post by peg
hi all,
Similar problem with javascript ?
datas = '{ "items":[ { "name": "item1" }, { "name": "item2" } ],
"show": "true" }'
template = "{.section items}{.section show} SHOW {.or} DON'T SHOW
{.end}{.or} NO ITEMS {.end}"
result = "DON'T SHOW"
thanks
We have similar problem - even with single section - if the section is
not null, nothing appears, if it is null, it correctly executes
{.or}
it's a serious bug - tried to look at source but couldn't see fix
right away - we really need a fix or workaround so would appreciate
any help. thks.
Post by peg
Post by j***@public.gmane.org
Owner: sroussey
Comment #1 on issue 55 by sroussey: Section names not looked up properlyhttp://code.google.com/p/json-template/issues/detail?id=55
I haven't contributed back the changes I've made recently. I think a fix
for this is
one of them (and it is elsewhere in the code). I'll get on this next week.
--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:http://code.google.com/hosting/settings
--
You received this message because you are subscribed to the Google Groups "JSON Template" group.
To post to this group, send email to json-template-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To unsubscribe from this group, send email to json-template+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit this group at http://groups.google.com/group/json-template?hl=en.
Steven Roussey
2010-03-26 18:19:33 UTC
Permalink
Where did you download json-template from, then?

Steven Roussey
Network54 Corp.
Post by MilesTogoe
Post by Steven Roussey
My JS version (that I use) has diverged quite a bit over time, and I
"true" };
template  = "{.section items}{.section show} SHOW {.or} DON'T SHOW
{.end}{.or} NO ITEMS {.end}"
t=jsontemplate.Template(template)
t.expand(data)
" SHOW "
Which json-template.js are you using?
Fedora 12
node v0.1.32-4
node-router
json-template - we don't see a version listed anywhere !  not in docs, not
in source !  we did download it about 2 wks ago but don't see our original
clone download date
Post by Steven Roussey
-steve--
Post by Miles
Post by peg
hi all,
     Similar problem with javascript ?
     datas =  '{ "items":[ { "name": "item1" },  { "name": "item2" } ],
"show": "true" }'
     template  = "{.section items}{.section show} SHOW {.or} DON'T SHOW
{.end}{.or} NO ITEMS {.end}"
     result = "DON'T SHOW"
     thanks
We have similar problem - even with single section - if the section is
not null, nothing appears, if it is null, it correctly executes
{.or}
it's a serious bug - tried to look at source but couldn't see fix
right away - we really need a fix or workaround so would appreciate
any help.   thks.
Post by peg
       Owner: sroussey
       Comment #1 on issue 55 by sroussey: Section names not looked up
properlyhttp://code.google.com/p/json-template/issues/detail?id=55
       I haven't contributed back the changes I've made recently. I
think a fix  for this is
one of them (and it is elsewhere in the code). I'll get on this next week.
       --
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences
at:http://code.google.com/hosting/settings
--
You received this message because you are subscribed to the Google Groups
"JSON Template" group.
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/json-template?hl=en.
--
You received this message because you are subscribed to the Google Groups "JSON Template" group.
To post to this group, send email to json-template-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To unsubscribe from this group, send email to json-template+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/json-template?hl=en.
MilesTogoe
2010-03-27 03:02:27 UTC
Permalink
Post by Steven Roussey
Where did you download json-template from, then?
we cloned it from github which of course has a commit id but once on our
system there is no version info with the source code or are we missing
something. Anyway it was downloaded about March 10.
Post by Steven Roussey
Steven Roussey
Network54 Corp.
Post by MilesTogoe
Post by Steven Roussey
My JS version (that I use) has diverged quite a bit over time, and I
"true" };
template = "{.section items}{.section show} SHOW {.or} DON'T SHOW
{.end}{.or} NO ITEMS {.end}"
t=jsontemplate.Template(template)
t.expand(data)
" SHOW"
Which json-template.js are you using?
Fedora 12
node v0.1.32-4
node-router
json-template - we don't see a version listed anywhere ! not in docs, not
in source ! we did download it about 2 wks ago but don't see our original
clone download date
Post by Steven Roussey
-steve--
Post by Miles
Post by peg
hi all,
Similar problem with javascript ?
datas = '{ "items":[ { "name": "item1" }, { "name": "item2" } ],
"show": "true" }'
template = "{.section items}{.section show} SHOW {.or} DON'T SHOW
{.end}{.or} NO ITEMS {.end}"
result = "DON'T SHOW"
thanks
We have similar problem - even with single section - if the section is
not null, nothing appears, if it is null, it correctly executes
{.or}
it's a serious bug - tried to look at source but couldn't see fix
right away - we really need a fix or workaround so would appreciate
any help. thks.
Post by peg
Post by j***@public.gmane.org
Owner: sroussey
Comment #1 on issue 55 by sroussey: Section names not looked up
properlyhttp://code.google.com/p/json-template/issues/detail?id=55
I haven't contributed back the changes I've made recently. I
think a fix for this is
one of them (and it is elsewhere in the code). I'll get on this next week.
--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences
at:http://code.google.com/hosting/settings
--
You received this message because you are subscribed to the Google Groups
"JSON Template" group.
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/json-template?hl=en.
--
You received this message because you are subscribed to the Google Groups "JSON Template" group.
To post to this group, send email to json-template-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To unsubscribe from this group, send email to json-template+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit this group at http://groups.google.com/group/json-template?hl=en.
peg
2010-04-13 09:34:19 UTC
Permalink
hi,
Sorry for being slow.
What version do you use ?
I'm using the
http://code.google.com/p/json-template/
git source version.

What is the difference with your version ?

thanks
Phil
Post by Steven Roussey
Where did you download json-template from, then?
Steven Roussey
Network54 Corp.
Post by MilesTogoe
Post by Steven Roussey
My JS version (that I use) has diverged quite a bit over time, and I
"true" };
template  = "{.section items}{.section show} SHOW {.or} DON'T SHOW
{.end}{.or} NO ITEMS {.end}"
t=jsontemplate.Template(template)
t.expand(data)
" SHOW "
Which json-template.js are you using?
Fedora 12
node v0.1.32-4
node-router
json-template - we don't see a version listed anywhere !  not in docs, not
in source !  we did download it about 2 wks ago but don't see our original
clone download date
Post by Steven Roussey
-steve--
Post by Miles
Post by peg
hi all,
     Similar problem with javascript ?
     datas =  '{ "items":[ { "name": "item1" },  { "name": "item2" } ],
"show": "true" }'
     template  = "{.section items}{.section show} SHOW {.or} DON'T SHOW
{.end}{.or} NO ITEMS {.end}"
     result = "DON'T SHOW"
     thanks
We have similar problem - even with single section - if the section is
not null, nothing appears, if it is null, it correctly executes
{.or}
it's a serious bug - tried to look at source but couldn't see fix
right away - we really need a fix or workaround so would appreciate
any help.   thks.
Post by peg
       Owner: sroussey
       Comment #1 on issue 55 by sroussey: Section names not looked up
properlyhttp://code.google.com/p/json-template/issues/detail?id=55
       I haven't contributed back the changes I've made recently. I
think a fix  for this is
one of them (and it is elsewhere in the code). I'll get on this next week.
       --
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences
at:http://code.google.com/hosting/settings
--
You received this message because you are subscribed to the Google Groups
"JSON Template" group.
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/json-template?hl=en.
--
You received this message because you are subscribed to the Google Groups "JSON Template" group.
To post to this group, send email to json-template-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To unsubscribe from this group, send email to json-template+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/json-template?hl=en.
j***@public.gmane.org
2010-03-26 02:22:24 UTC
Permalink
Updates:
Status: Started

Comment #2 on issue 55 by sroussey: Section names not looked up properly
http://code.google.com/p/json-template/issues/detail?id=55

I'm not on my normal PC, so I don't have the test harness setup, so I
pushed a change
to the sroussey-json-template repo. There were many logic errors,
particularly with
scopes. I wish I had update the repo as I fixed them, but instead they are
all in one
big change. I'm checking on the JS version that I use, and will update that
as well if
warranted.

--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:
http://code.google.com/hosting/settings
--
You received this message because you are subscribed to the Google Groups "JSON Template" group.
To post to this group, send email to json-template-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To unsubscribe from this group, send email to json-template+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit this group at http://groups.google.com/group/json-template?hl=en.
j***@public.gmane.org
2010-08-19 03:04:03 UTC
Permalink
Comment #3 on issue 55 by nadir.seen.fire: Section names not looked up
properly
http://code.google.com/p/json-template/issues/detail?id=55

I believe this issue affects more than just the PHP and Python, it seams to
be present as well I believe.

While using JSON-Template I've had issues with higher level names not being
looked up properly in the same way described. One time I rewrote the logic
of a template in a somewhat unintuitive way to get around it. Now I appear
to have run into another one which will be more trouble. I may have to
switch template systems.
--
You received this message because you are subscribed to the Google Groups "JSON Template" group.
To post to this group, send email to json-template-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To unsubscribe from this group, send email to json-template+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit this group at http://groups.google.com/group/json-template?hl=en.
Loading...