j***@public.gmane.org
2010-03-05 06:44:50 UTC
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
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.
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.