Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Silent truncation of diet templates when rendering non-string Json node #714

Closed
luismarques opened this issue Jul 8, 2014 · 1 comment
Closed

Comments

@luismarques
Copy link

Given the vibe.d code:

auto j = parseJsonString(`{"foo": 42}`);
auto foo = j.foo;
res.render!("test.dt", foo);

and a template like:

doctype html
html
    head
        title Bug
    body
        p before
        p= foo
        p after

You will only get the content until "before". Everything after is silently dropped. This can be worked around by using something like:

auto j = parseJsonString(`{"foo": 42}`);
auto foo = j.foo.get!int;
res.render!("test.dt", foo);

I think the diet renderer should be able to work with raw Json nodes (without using get!T or to!T), but in any case it should not truncate the output silently.

@s-ludwig
Copy link
Member

s-ludwig commented Jul 9, 2014

The root cause is that the p= foo will issue a cast(string)foo, which in turn calls foo.get!string(). However, the type is int, so an exception is thrown, hence the cut off page (run the application with -v or --vv to see the exception). I think in this case, it will be safe to change the rule of how values are converted to strings in vibe.templ.diet._toString. Instead of trying to cast(), try to use toString() first (currently this is done only if casting isn't possible).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants