Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Add support for '}' characters within string literals in data-link expressions #55

Closed
govis opened this Issue Mar 20, 2012 · 8 comments

Comments

Projects
None yet
2 participants

govis commented Mar 20, 2012

Hi Boris,

Trying to upgrade from the previous version I encountered the following issue.

I use data-link converter functions as follows:
data-link="{:~formatterFunc('Showing {0} items in {1} folder', ItemCount, FolderName)}"

Where formatterFunc helper is something similar to String.Format in .NET.

With your latest bits I get an error during a call to $.link("#container", data)
“Unterminated string constant”.

If I remove the {0} and {1} from the string, it works fine. Also if was working with the last version of jsViews.

Error is coming form
function linkViews( node, parent, nextNode, depth, data, context, prevNode, index ) { .. }, which seems to be parsing the string literals.

It is turning out to be a great library so far, keep up the great work.

Thanks.

govis commented Mar 21, 2012

Now that I think more about it, it might even be beneficial if you allow for linking anchors inside strings, so we can do smth like data-link="{:'Showing {:ItemCount} items in {:FolderName} folder'}". You still may need to consider coming up with a way to escape those brackets when necessary though.

Owner

BorisMoore commented Mar 21, 2012

I'll look at changing the parsing so it can skip over the }. But for now you can of course use a different character, and then string replace if you need to, within your formatterFunc.

="{:~formatterFunc('Showing [0] items in [1] folder', ItemCount, FolderName)}"

Right now the one character that is problematic is }.

govis commented Mar 21, 2012

Thanks for looking into this Boris.

Yes, using different characters could work for me as a workaround or calling the format function to dynamically generate the linking expression with {{:}} instead. The strings are coming from resource files shared with a .NET application hence the {x} syntax. I think this issue might also manifest itself if somebody was trying to pass a snippet of javascript code as a string too - do you think it might be a valid use case.

I wonder if we used double brackets instead, do you think this would be more consistent with jsRender syntax that way?
="{{:~formatterFunc('Showing {0} items in {1} folder', ItemCount, FolderName)}}"

Thanks

Owner

BorisMoore commented Mar 21, 2012

Double brackets will break tag parsing, e.g. {{if foo}} <span data--link="{{...}}">/<span>{{/if}}.
I have a plan for getting single brackets to work, though...

Owner

BorisMoore commented Feb 28, 2013

In string literals,you can use character entities: Replace } with }

For example data-link="{:~formatterFunc('Showing {0&#125; items in {1&#125; folder', ItemCount, FolderName)}"

Can you test whether that works for you?

Owner

BorisMoore commented Apr 9, 2013

@govis: - didn't hear back. Closing this for now.

@BorisMoore BorisMoore closed this Apr 9, 2013

@BorisMoore BorisMoore reopened this Apr 9, 2013

Owner

BorisMoore commented Apr 9, 2013

On second thoughts, keeping this open as a request to support '}' characters in string literals within data-link expressions. Changing the title too...

Example:
<div data-link="a + '}' + b"></div>

For now the workaround is
<div data-link="a + '&#125;' + b"></div>

Owner

BorisMoore commented Sep 2, 2015

Closing "After V1.0" issues for now - to reopen as appropriate.

@BorisMoore BorisMoore closed this Sep 2, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment