A string escape issue with Yesod Julius
Greetings Recently I stumbled upon an unexpected escaping problem. I hoped Shakespeare templates would solve these forever, but looks like it's not the case. For example, look at this snippet: Prelude Text.Julius Data.Text.Lazy Data.Text> let t = "X\"Y\"Z"; j = [julius| str = "a#{t}bc"; |] in putStrLn $ Data.Text.Lazy.unpack $ renderJavascriptUrl (\u env -> Data.Text.pack "") j str = "aX"Y"Zbc"; Clearly we have have a problem here. Can something be done with it? Best wishes, Dmitry
Your question would be better answered on the yesod (google group) mail list. Julius is fairly dumb about interpolation as you point out. Eventually we would like to make all insertions be JSON values. On Wed, Nov 14, 2012 at 2:08 AM, Dmitry Vyal <akamaus@gmail.com> wrote:
Greetings
Recently I stumbled upon an unexpected escaping problem. I hoped Shakespeare templates would solve these forever, but looks like it's not the case.
For example, look at this snippet: Prelude Text.Julius Data.Text.Lazy Data.Text> let t = "X\"Y\"Z"; j = [julius| str = "a#{t}bc"; |] in putStrLn $ Data.Text.Lazy.unpack $ renderJavascriptUrl (\u env -> Data.Text.pack "") j str = "aX"Y"Zbc";
Clearly we have have a problem here. Can something be done with it?
Best wishes, Dmitry
______________________________**_________________ web-devel mailing list web-devel@haskell.org http://www.haskell.org/**mailman/listinfo/web-devel<http://www.haskell.org/mailman/listinfo/web-devel>
You could solve this in one of two ways: 1. Switch over to embedding `t` as JSON and concatenating in Javascript, e.g.: [julius| str = "a" + #{toJSON t} + "bc"|]. I think we never ended up adding the aeson instances to shakespeare-js, but I'm in favor of doing so. 2. Writing some escape algorithm on the characters. This would be more complicated. The reason we haven't implemented the idea that Greg mentions is that it prevents certain use cases, such as interpolating actual Javascript code. On Wed, Nov 14, 2012 at 12:08 PM, Dmitry Vyal <akamaus@gmail.com> wrote:
Greetings
Recently I stumbled upon an unexpected escaping problem. I hoped Shakespeare templates would solve these forever, but looks like it's not the case.
For example, look at this snippet: Prelude Text.Julius Data.Text.Lazy Data.Text> let t = "X\"Y\"Z"; j = [julius| str = "a#{t}bc"; |] in putStrLn $ Data.Text.Lazy.unpack $ renderJavascriptUrl (\u env -> Data.Text.pack "") j str = "aX"Y"Zbc";
Clearly we have have a problem here. Can something be done with it?
Best wishes, Dmitry
______________________________**_________________ web-devel mailing list web-devel@haskell.org http://www.haskell.org/**mailman/listinfo/web-devel<http://www.haskell.org/mailman/listinfo/web-devel>
On 11/15/2012 09:48 AM, Michael Snoyman wrote:
You could solve this in one of two ways:
1. Switch over to embedding `t` as JSON and concatenating in Javascript, e.g.: [julius| str = "a" + #{toJSON t} + "bc"|]. I think we never ended up adding the aeson instances to shakespeare-js, but I'm in favor of doing so. 2. Writing some escape algorithm on the characters. This would be more complicated.
The reason we haven't implemented the idea that Greg mentions is that it prevents certain use cases, such as interpolating actual Javascript code.
The first way works wonderfully, thanks! Speaking about corner use cases, that's reminds me situation with #{} and ^{} in Hamlet. Why not to go the same route in Julius? Dmitry
participants (3)
-
Dmitry Vyal -
Greg Weber -
Michael Snoyman