• Login
sketchucation logo sketchucation
  • Login
⚠️ Libfredo 15.4b | Minor release with bugfixes and improvements Update

Webdialog to ruby encoding issue on OSX

Scheduled Pinned Locked Moved Developers' Forum
22 Posts 5 Posters 730 Views 5 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    jiminy-billy-bob
    last edited by 25 May 2014, 20:54

    I think I've read something about this a while ago, but can't find it anymore. If anyone has a link...?

    Anyway, I have an issue with string encoding in webdialog callbacks on OSX. When a string is passed as a parameter, ruby doesn't display special characters correctly.
    Like "ç" becomes "√ß".
    Every rb, html and js file is of course UTF-8 encoded. It breaks even if I try a .force_encoding("utf-8") on the returned string (in SU2014).

    It works fine on Windows 7.

    Any thought?

    25% off Skatter for SketchUcation Premium Members

    1 Reply Last reply Reply Quote 0
    • D Offline
      Dan Rathbun
      last edited by 25 May 2014, 21:37

      If you query for the encoding upon the returned string (before forcing,) what do you get ?

      I'm not here much anymore.

      1 Reply Last reply Reply Quote 0
      • D Offline
        Dan Rathbun
        last edited by 25 May 2014, 21:39

        @jiminy-billy-bob said:

        I think I've read something about this a while ago, but can't find it anymore. If anyone has a link...?

        Probably this:

        WebDialog encoding bug found!

        I'm not here much anymore.

        1 Reply Last reply Reply Quote 0
        • D Offline
          driven
          last edited by 25 May 2014, 22:19

          I think it is the thread dan points to...

          converting to unicode literal based on the string before retrieving/sending was the only thing that worked for me...

          the js from the test rb

          
                /* Creates a uppercase hex number with at least length digits from a given number */
                function fixedHex(number, length){
                    var str = number.toString(16).toUpperCase();
                    while(str.length < length)
                        str = "0" + str;
                    return str;
                }
          
                /* Creates a unicode literal based on the string. nts; UTF-8 is an encoding - Unicode is a character set*/
                function unicodeLiteral(str){
                    var i;
                    var result = "";
                    for( i = 0; i < str.length; ++i){
                        /* You should probably replace this by an isASCII test */
                        if(str.charCodeAt(i) > 126 || str.charCodeAt(i) < 32)
                            result += "\\\\" + "u" + fixedHex(str.charCodeAt(i),4);
                        else
                            result += str[i];
                    }
              return result;
          }
          

          john

          learn from the mistakes of others, you may not live long enough to make them all yourself...

          1 Reply Last reply Reply Quote 0
          • J Offline
            jiminy-billy-bob
            last edited by 27 May 2014, 17:59

            This is the one, thanks guys!

            25% off Skatter for SketchUcation Premium Members

            1 Reply Last reply Reply Quote 0
            • J Offline
              jiminy-billy-bob
              last edited by 28 May 2014, 14:59

              John, your solution works well when sending the string back to the webdialog. But in my case I'm trying to read the string inside ruby (actually change layers names).
              The problem is that ruby reads the unicode as is, without converting to actual characters. I end up with layers called something like "\u00E9" in SU's layer window (But it displays fine in my webdialog)

              I can't find a solution on google. Do you guys have any idea what I should do?

              25% off Skatter for SketchUcation Premium Members

              1 Reply Last reply Reply Quote 0
              • T Offline
                tt_su
                last edited by 28 May 2014, 18:56

                @jiminy-billy-bob said:

                The problem is that ruby reads the unicode as is, without converting to actual characters.

                ❓

                Is it execute_script being the issue? (Sorry, loooong thread - got confused.)

                1 Reply Last reply Reply Quote 0
                • D Offline
                  driven
                  last edited by 28 May 2014, 19:27

                  @jiminy-billy-bob said:

                  The problem is that ruby reads the unicode as is, without converting to actual characters. I end up with layers called something like "\u00E9" in SU's layer window

                  are you single quoting it?

                  > "\u00E9"
                  é
                  > '\u00E9'
                  \u00E9
                  > %q(\u00E9)
                  \u00E9
                  > %Q(\u00E9)
                  é
                  

                  or maybe use .inspect?

                  "\u00E9".inspect
                  "é"
                  

                  else
                  post a snippet, and I'll run some checks...

                  I did write a ruby encode/decode, but didn't need it for what I was doing...

                  I'll see if I kept it

                  john

                  learn from the mistakes of others, you may not live long enough to make them all yourself...

                  1 Reply Last reply Reply Quote 0
                  • T Offline
                    tt_su
                    last edited by 28 May 2014, 21:13

                    Is your HTML in UTF-8 and tagged with a UTF-8 meta tag so the HTML engine knows to use UTF8?
                    I tried that ç character in SKUI and it renders fine:
                    2014-05-28_23h08_54.png

                    I'm not doing anything special, other than ensuring the my RB files are UTF-8 encoded, that my HTML files are UTF-8 encoded (with UTF-8 characterset META tag.)

                    1 Reply Last reply Reply Quote 0
                    • T Offline
                      tt_su
                      last edited by 28 May 2014, 21:21

                      Ditto on OSX:

                      2014-05-28_23h17_20.png

                      I think we need a full example of the error you get - packaged up as RBZ.

                      1 Reply Last reply Reply Quote 0
                      • T Offline
                        tt_su
                        last edited by 28 May 2014, 21:22

                        Btw, what is the source for this character?

                        1 Reply Last reply Reply Quote 0
                        • D Offline
                          driven
                          last edited by 28 May 2014, 21:44

                          @TT

                          the third last post from the other thread has a rbz that shows the issue on a mac...
                          http://sketchucation.com/forums/viewtopic.php?f=180%26amp;t=57074%26amp;start=30#p518959

                          returns using 'get_element_value' have bad encoding regardless of html declarations, script encodings, etc...

                          something is happening internally in SU that screws things up...

                          try the rbz it's harmless...

                          john

                          learn from the mistakes of others, you may not live long enough to make them all yourself...

                          1 Reply Last reply Reply Quote 0
                          • D Offline
                            Dan Rathbun
                            last edited by 28 May 2014, 22:24

                            Did someone file a bug report ?

                            I'm not here much anymore.

                            1 Reply Last reply Reply Quote 0
                            • D Offline
                              driven
                              last edited by 28 May 2014, 22:39

                              @dan rathbun said:

                              Did someone file a bug report ?

                              I was going to but I got distracted by work and it's still on my endless todo list...

                              john

                              learn from the mistakes of others, you may not live long enough to make them all yourself...

                              1 Reply Last reply Reply Quote 0
                              • T Offline
                                tt_su
                                last edited by 29 May 2014, 09:05

                                @driven said:

                                the third last post from the other thread has a rbz that shows the issue on a mac...
                                http://sketchucation.com/forums/viewtopic.php?f=180%26amp;t=57074%26amp;start=30#p518959

                                So this only happen on OSX, not on Windows?

                                1 Reply Last reply Reply Quote 0
                                • D Offline
                                  driven
                                  last edited by 29 May 2014, 19:48

                                  @tt_su said:

                                  So this only happen on OSX, not on Windows?

                                  as far as I'm aware it's a mac thing...

                                  I think it's because the internal bash env locale defaults to "C" if not implicedly set

                                  > %x(locale)
                                  LANG=
                                  LC_COLLATE="C"
                                  LC_CTYPE="C"
                                  LC_MESSAGES="C"
                                  LC_MONETARY="C"
                                  LC_NUMERIC="C"
                                  LC_TIME="C"
                                  LC_ALL=
                                  

                                  whereas same call in 'Terminal.app'

                                  LANG="en_US"
                                  LC_COLLATE="en_US.UTF-8"
                                  LC_CTYPE="en_US.UTF-8"
                                  LC_MESSAGES="en_US.UTF-8"
                                  LC_MONETARY="en_US.UTF-8"
                                  LC_NUMERIC="en_US.UTF-8"
                                  LC_TIME="en_US.UTF-8"
                                  LC_ALL="en_US.UTF-8"
                                  

                                  because it is set...
                                  john

                                  learn from the mistakes of others, you may not live long enough to make them all yourself...

                                  1 Reply Last reply Reply Quote 0
                                  • J Offline
                                    jiminy-billy-bob
                                    last edited by 30 May 2014, 12:46

                                    @driven said:

                                    post a snippet, and I'll run some checks...

                                    Going back to your test here

                                    If you add

                                    Sketchup.active_model.layers.add param_fix
                                    

                                    in @dlg2.add_action_callback("trans_L8_fix")

                                    The layer name is displayed "élan 勢い Schwung импульс" in Layers Panel, as it is a webdialog.
                                    But in Sketchup's layer window, it's displayed "\u00E9lan \u52E2\u3044 Schwung \u0438\u043C\u043F\u0443\u043B\u044C\u0441", just like what's printed in the ruby console.

                                    Any thought on that?

                                    TT > Yes, everything is set to UTF-8. Encoding, meta-tags

                                    25% off Skatter for SketchUcation Premium Members

                                    1 Reply Last reply Reply Quote 0
                                    • S Offline
                                      slbaumgartner
                                      last edited by 30 May 2014, 12:52

                                      @driven said:

                                      @tt_su said:

                                      So this only happen on OSX, not on Windows?

                                      as far as I'm aware it's a mac thing...

                                      I think it's because the internal bash env locale defaults to "C" if not implicedly set

                                      > %x(locale)
                                      > LANG=
                                      > LC_COLLATE="C"
                                      > LC_CTYPE="C"
                                      > LC_MESSAGES="C"
                                      > LC_MONETARY="C"
                                      > LC_NUMERIC="C"
                                      > LC_TIME="C"
                                      > LC_ALL=
                                      

                                      whereas same call in 'Terminal.app'

                                      LANG="en_US"
                                      > LC_COLLATE="en_US.UTF-8"
                                      > LC_CTYPE="en_US.UTF-8"
                                      > LC_MESSAGES="en_US.UTF-8"
                                      > LC_MONETARY="en_US.UTF-8"
                                      > LC_NUMERIC="en_US.UTF-8"
                                      > LC_TIME="en_US.UTF-8"
                                      > LC_ALL="en_US.UTF-8"
                                      

                                      because it is set...
                                      john

                                      I think this is because SU does not set ENV["LANG"] when launching the subshell.

                                      Steve

                                      1 Reply Last reply Reply Quote 0
                                      • D Offline
                                        driven
                                        last edited by 30 May 2014, 20:32

                                        @ Steve
                                        do you think the two are unrelated?

                                        @jiminy-billy-bob said:

                                        Any thought on that?

                                        if I eval it double quoted, I get élan 勢い Schwung импульс

                                            puts (eval('"' + param_fix + '"'))
                                        

                                        works in UI.messagebox that way as well.

                                        alternatively I wrote [so it is possible] a simple decode method by reversing the JS function back in ruby, it worked but i can't find it...

                                        john

                                        learn from the mistakes of others, you may not live long enough to make them all yourself...

                                        1 Reply Last reply Reply Quote 0
                                        • J Offline
                                          jiminy-billy-bob
                                          last edited by 30 May 2014, 20:42

                                          eval works great, thanks!

                                          25% off Skatter for SketchUcation Premium Members

                                          1 Reply Last reply Reply Quote 0
                                          • 1
                                          • 2
                                          • 1 / 2
                                          1 / 2
                                          • First post
                                            1/22
                                            Last post
                                          Buy SketchPlus
                                          Buy SUbD
                                          Buy WrapR
                                          Buy eBook
                                          Buy Modelur
                                          Buy Vertex Tools
                                          Buy SketchCuisine
                                          Buy FormFonts

                                          Advertisement