[Rails] Re: javascript encodeURIComponent equal code

2009-05-19 Thread Qi Xiang
Nanyang Zhan wrote: > Frederick Cheung wrote: >> I'd no idea where D6D0 is >> coming from > > OK, problem solved. Thank you, Fred. I may never have it done without > your help. > > It turns out %D6%D0%CE%C4 is not a utf16 relate result, but a GB2312 > encoding production. > > I convert the s

[Rails] Re: javascript encodeURIComponent equal code

2009-03-31 Thread Nanyang Zhan
Frederick Cheung wrote: > I'd no idea where D6D0 is > coming from OK, problem solved. Thank you, Fred. I may never have it done without your help. It turns out %D6%D0%CE%C4 is not a utf16 relate result, but a GB2312 encoding production. I convert the string from utf8 to GB2312 with iconv, th

[Rails] Re: javascript encodeURIComponent equal code

2009-03-31 Thread Frederick Cheung
On Mar 31, 5:04 pm, Nanyang Zhan wrote: > > when:>> "中文".unpack("U*") > > => [20013, 25991] > > So, it is a way turning [20013, 25991] to '%D6%D0%CE%C4', right? > Well 20013 is 0x4E2D which is the utf16 for the first of your characters. Looking back at what you write I'd no idea where D6D0 is

[Rails] Re: javascript encodeURIComponent equal code

2009-03-31 Thread Nanyang Zhan
Frederick Cheung wrote: > well s.unpack("U*") will turn a string into a array of integers (utf > code points) that it should then be easy to split into bytes. I'd > start from scratch rather than using url_encode though. Thanks! Fred. >> "中文".unpack("C*") => [228, 184, 173, 230, 150, 135] > ERB

[Rails] Re: javascript encodeURIComponent equal code

2009-03-31 Thread Frederick Cheung
On Mar 31, 4:44 pm, Nanyang Zhan wrote: > Frederick Cheung wrote: > > Those aren't playing with encodings which is apparently the issue > > here. Why does it matter anyway? > > ok. > > Here is the source code of ERB::Util.url_encode(s) method. > # File erb.rb, line 801 >     def url_encode(s) >

[Rails] Re: javascript encodeURIComponent equal code

2009-03-31 Thread Nanyang Zhan
Frederick Cheung wrote: > Those aren't playing with encodings which is apparently the issue > here. Why does it matter anyway? ok. Here is the source code of ERB::Util.url_encode(s) method. # File erb.rb, line 801 def url_encode(s) s.to_s.gsub(/[^a-zA-Z0-9_\-.]/n){ sprintf("%%%02X",

[Rails] Re: javascript encodeURIComponent equal code

2009-03-31 Thread Frederick Cheung
On Mar 31, 4:27 pm, Nanyang Zhan wrote: > Frederick Cheung wrote: > > Well the difference is that the javascript stuff is produced UTF16 and > > the ruby UTF8 (although the documentation I can find suggests that the > > javascript should also be producing utf8).ith ruby code? > > Thank you for

[Rails] Re: javascript encodeURIComponent equal code

2009-03-31 Thread Nanyang Zhan
Frederick Cheung wrote: > Well the difference is that the javascript stuff is produced UTF16 and > the ruby UTF8 (although the documentation I can find suggests that the > javascript should also be producing utf8).ith ruby code? Thank you for your replied. May be it is the true. But how can the u

[Rails] Re: javascript encodeURIComponent equal code

2009-03-31 Thread Frederick Cheung
On Mar 31, 2:06 pm, Nanyang Zhan wrote: > Javascript's encodeURIComponent works differently from CGI.eacape or > ERB::Util.u. Well the difference is that the javascript stuff is produced UTF16 and the ruby UTF8 (although the documentation I can find suggests that the javascript should also be