Trouble with wf:wire and utf/8 encoding

36 views
Skip to first unread message

Sebastien Saint-Sevin

unread,
Jun 24, 2015, 12:39:01 PM6/24/15
to nitro...@googlegroups.com
Hi Jesse,

Still porting some apps to new version (2.3.1).
I isolated another trouble with utf8 encoding in javascript wiring.

Here is some code to show it :

%% -*- coding: utf-8 -*-
-module(test).
-compile(export_all).
-include_lib("nitrogen_core/include/wf.hrl").

main() -> #template{file="./site/templates/index.html"}.

main_div_body() ->
    [#panel{id=form, body=
  [#span{id=label, text="Subject with accent éùà"},
  #button{text="click me", postback={btn, click}}]
  }].

event({btn, click}) ->
wf:wire(wf:js_escape("var myvar='éùà';")).

%% *****************************************************************************
%% END OF FILE
%% -----------------------------------------------------------------------------

When I click on the button, I've got an error client side saying the transmitted string is malformed.

Cheers,

Sébastien.


Jesse Gumm

unread,
Jun 26, 2015, 5:43:42 PM6/26/15
to nitrogenweb
Hi Sebastien,

Sorry for the super-long delay here. It's been a busy week and this
slipped through the cracks.

I'm looking into this tonight and will get back to you on it.

-Jesse
> --
> You received this message because you are subscribed to the Google Groups
> "Nitrogen Project / The Nitrogen Web Framework for Erlang" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to nitrogenweb...@googlegroups.com.
> To post to this group, send email to nitro...@googlegroups.com.
> Visit this group at http://groups.google.com/group/nitrogenweb.
> For more options, visit https://groups.google.com/d/optout.



--
Jesse Gumm
Owner, Sigma Star Systems
414.940.4866 || sigma-star.com || @jessegumm

Sebastien Saint-Sevin

unread,
Jul 1, 2015, 8:46:42 AM7/1/15
to nitro...@googlegroups.com
Hi Jesse,

Did you had a chance to have a look to it ?

Cheers,

Sébastien.

Jesse Gumm

unread,
Jul 1, 2015, 9:33:17 AM7/1/15
to nitrogenweb

My apologies, I got sidetracked down a rabbit hole. I'll have a look at it today for sure.

-Jesse

Jesse Gumm

unread,
Jul 2, 2015, 2:42:27 AM7/2/15
to nitrogenweb
I'll have a fix for this posted tomorrow, but for now, this will get you going:

1) Your use of wf:js_escape here is unnecessary and will cause trouble
in your app. wf:js_escape is more relevant for when you have to
escape a string to be contained within another javascript string.
Here, you can just do wf:wire(CodeToRun).

2) As for the utf encoding, for now, just passing it as a utf8 binary
will get the job done: wf:wire(<<"var myvar='éùà';"/utf8>>)

That said, I'll have a fix for (2) posted tomorrow. I've got it
working on my machine right now, but I'm getting a little delirious
and need to get some sleep (almost 2am), so no working to push the fix
out tonight, not at least until I've run it through the test suite.

-Jesse

Jesse Gumm

unread,
Jul 2, 2015, 1:53:51 PM7/2/15
to nitrogenweb
Alrighty, a new version has been pushed up to master which should work
with the original code (minus the wf:js_escape).

-Jesse

Jesse Gumm

unread,
Jul 3, 2015, 8:53:54 PM7/3/15
to nitrogenweb
If you haven't merged in the changes yet, hold off - I found a pretty
bad bug as a result of a refactoring. I'll post when it's fixed.

-Jesse

Jesse Gumm

unread,
Jul 3, 2015, 11:35:18 PM7/3/15
to nitrogenweb
Huge bug fixed. Sorry about that. Feel free to pull from master now.
Reply all
Reply to author
Forward
0 new messages