Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Issue 68 in json-template: HTML formatter doesn't work for numeric values
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
json-templ...@googlecode.com  
View profile  
 More options Jan 13 2012, 4:34 pm
From: json-templ...@googlecode.com
Date: Fri, 13 Jan 2012 21:34:48 +0000
Local: Fri, Jan 13 2012 4:34 pm
Subject: Issue 68 in json-template: HTML formatter doesn't work for numeric values
Status: New
Owner: ----
Labels: Type-Defect Priority-Medium

New issue 68 by bharbu...@gmail.com: HTML formatter doesn't work for  
numeric values
http://code.google.com/p/json-template/issues/detail?id=68

What steps will reproduce the problem?
1. Put a JSON numeric value in the variables to use.
2. Use the {{{'html'}}} formatter.

What is the expected output? What do you see instead?

This will produce a {{{TypeError}}} exception, since it tries to call  
{{{replace}}} on the value. Turning the number into a string would be more  
meaningful.

What version of the product are you using? On what operating system?

The latest at this time:  
http://code.google.com/p/json-template/source/browse/javascript/json-...

Please provide any additional information below.

There is an example here: http://jsfiddle.net/vUhG5/

The following fails:

{{{
var testData = {
     var_a: '10001',
     var_b: 10002

};

var t = jsontemplate.fromString('var_a={var_a} and var_b={var_b}', {  
default_formatter: 'html' });
var txt = t.expand(testData);

}}}

The error is within function {{{HtmlEscape}}}, at line 55: {{{var_b}}} is  
not a string and doesn't have a {{{replace}}} method.

Doing {{{s.toString().replace(...)....}}} instead of {{{s.replace(...)}}}  
should fix the problem.

The same issue applies to {{{HtmlTagEscape}}} just below, of course.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
json-templ...@googlecode.com  
View profile  
 More options Jan 13 2012, 5:04 pm
From: json-templ...@googlecode.com
Date: Fri, 13 Jan 2012 22:04:02 +0000
Local: Fri, Jan 13 2012 5:04 pm
Subject: Re: Issue 68 in json-template: HTML formatter doesn't work for numeric values

Comment #1 on issue 68 by andyc...@gmail.com: HTML formatter doesn't work  
for numeric values
http://code.google.com/p/json-template/issues/detail?id=68

I think you should be able to use

{foo|str|html}

now.  That will convert the number to a string and them to html.

There might be some behavior change warranted -- I did tweak this in the  
Python version I think.

(Although, you don't need to ever escape numbers in HTML... so leaving it  
out altogether works too)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
json-templ...@googlecode.com  
View profile   Translate to Translated (View Original)
 More options Jan 13 2012, 5:38 pm
From: json-templ...@googlecode.com
Date: Fri, 13 Jan 2012 22:38:20 +0000
Local: Fri, Jan 13 2012 5:38 pm
Subject: Re: Issue 68 in json-template: HTML formatter doesn't work for numeric values

Comment #2 on issue 68 by bharbu...@gmail.com: HTML formatter doesn't work  
for numeric values
http://code.google.com/p/json-template/issues/detail?id=68

Thank you. This works indeed, but this is mainly a problem when relying on  
the default_formatter. I may have missed something in the documentation,  
but I haven't seen a "post_formatter", which would be applied to anything,  
after any specific formatter.

> Although, you don't need to ever escape numbers in HTML... so leaving it  
> out altogether works too

This works if I know in advance that it's going to be a number and not an  
arbitrary string with some characters that need to be escaped.

I was considering using { default_formatter: 'html' } as a short-cut for  
putting "|html" after each variable name.

If you don't know whether your data is { foo: 1 } or { foo: '<escape me>'  

}, at the moment, it seems you have to put "|str|html" behind every  

variable ("str|html" doesn't work as a default formatter).

In addition, I would also like the flexibility to change the  
default_formatter (admittedly, more as a "post-processor" formatter, which  
isn't what it's meant for) independently of the template itself, depending  
on what the target output would be. Even if I knew that foo was a number in  
advance, "foo|str" would replace the default formatter, not apply it before  
passing it to the html formatter.

(Ultimately, I think this is a bug in the HTML formatters because they  
expect a string as an input, which numbers are not, despite being valid  
JSON tokens.)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »