bsed / json-template

Automatically exported from code.google.com/p/json-template
0 stars 0 forks source link

PHP port does not correctly handle repeated sections #51

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
You can compare the Python version with the PHP version by running this simple 
test from the command line.  It works correctly in 
Python, and fails in PHP.

$ python expand.py '{.repeated section list}{.section test}{@index}. Test is 
TRUE{.newline}{.or}{@index}. Test is 
FALSE{.newline}{.end}{.end}' '{"list": [{"test": true},{"test": false},{"test": 
true},{"test": false}]}'
1. Test is TRUE
2. Test is FALSE
3. Test is TRUE
4. Test is FALSE

$ php -f jsontemplate_cmd.php '{.repeated section list}{.section test}{@index}. 
Test is TRUE{.newline}{.or}{@index}. Test is 
FALSE{.newline}{.end}{.end}' '{"list": [{"test": true},{"test": false},{"test": 
true},{"test": false}]}'
1. Test is TRUE
2. Test is FALSE

What is the expected output? What do you see instead?
The results of the template should be 4 lines of output, as seen with the 
Python version.  In PHP, it exists after the first two lines. 

What version of the product are you using? On what operating system?
I have the latest from Mercurial repository.

Please provide any additional information below.
It seems like the PHP port fails when there is a {.section} inside of the 
{.repeated section}.  This may be messing up its internal stack.

Original issue reported on code.google.com by brian.ho...@gmail.com on 10 Feb 2010 at 9:36

GoogleCodeExporter commented 9 years ago
This actually appears to be related to handling of boolean JSON values.  If, 
instead of "False", the value of "test" 
is undefined, then the PHP port gives the expected output.

$ php -f jsontemplate_cmd.php '{.repeated section list}{.section test}{@index}. 
Test is 
TRUE{.newline}{.or}{@index}. Test is 
FALSE{.newline}{.end}{.end}' '{"list": [{"test": true},{},{"test": true},{}]}'
1. Test is TRUE
2. Test is FALSE
3. Test is TRUE
4. Test is FALSE

Original comment by brian.ho...@gmail.com on 11 Feb 2010 at 1:22

GoogleCodeExporter commented 9 years ago

Original comment by sroussey on 18 Feb 2010 at 2:32