Hi, I''m in trouble with encoding again. I have a text area. Where I can enter sentences. And when a sentence that contains multiple lines is typed I get this into the DB: (json serialized) --- "{\"text\":[\"line one\\r\\nline two\"]}" Ok. When I take it from the db I see it like this in the controller: {"line one\r\nline two"=>"text"} (I have done something in between to change the order but that''s irrelevant) But you can see the \r\n in it. The thing is that in the view I need to pass it via javascript to a function that re-creates the text area dynamically. But the function gives the error: "Uncaught SyntaxError: Unexpected token ILLEGAL" For the javascript function I can use <%= CGI::escape(@thestring) %> and then the text area is created and the line breaks respected. That would be a way out. BUT. If any of the letters contain an accent, like í, then CGI::escape displays the letters with accents incorrectly. Instead of í I get Ã... I cannot find a way to live with both, accents and line breaks. Any ideas? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On May 20, 2011, at 4:44 PM, comopasta Gr wrote:> Hi, > > I''m in trouble with encoding again. > I have a text area. Where I can enter sentences. And when a sentence > that contains multiple lines is typed I get this into the DB: > > (json serialized) > > --- "{\"text\":[\"line one\\r\\nline two\"]}" > > Ok. When I take it from the db I see it like this in the controller: > {"line one\r\nline two"=>"text"} > (I have done something in between to change the order but that''s > irrelevant) > But you can see the \r\n in it. > > The thing is that in the view I need to pass it via javascript to a > function that re-creates the text area dynamically. > > But the function gives the error: "Uncaught SyntaxError: Unexpected > token ILLEGAL"From this week''s JavaScript Weekly newsletter: JSON: The JavaScript subset that isn''t? Magnus Holm notes that while JSON is meant to also be syntactically legal JavaScript code.. it isn''t always. What has Magnus discovered? Find out here. http://timelessrepo.com/json-isnt-a-javascript-subset?utm_source=javascriptweekly&utm_medium=email -Rob> > For the javascript function I can use <%= CGI::escape(@thestring) %> > and > then the text area is created and the line breaks respected. That > would > be a way out. > > BUT. If any of the letters contain an accent, like í, then CGI::escape > displays the letters with accents incorrectly. Instead of í I get > Ã ... > > I cannot find a way to live with both, accents and line breaks. > > Any ideas? > > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google > Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails- > talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com > . > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en > . >Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org +1 513-295-4739 Skype: rob.biedenharn -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> From this week''s JavaScript Weekly newsletter: > > JSON: The JavaScript subset that isn''t? > Magnus Holm notes that while JSON is meant to also be syntactically > legal JavaScript code.. it isn''t always. What has Magnus discovered? > Find out here. > >http://timelessrepo.com/json-isnt-a-javascript-subset?utm_source=javascriptweekly&utm_medium=email> > -Rob > > >> >> To post to this group, send email to rubyonrails- >> talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org >> . >> For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en >> . >> > > Rob Biedenharn http://agileconsultingllc.com > Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org > +1 513-295-4739 > Skype: rob.biedenharnHi, thanks. Just don''t see how to use the solution. I have used the patched rack middleware proposed but the problem remains. I guess it looks for U+2028 or U+2029 but I guess they are not present in my case... -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On May 20, 2011, at 6:19 PM, comopasta Gr wrote:>> From this week''s JavaScript Weekly newsletter: >> >> JSON: The JavaScript subset that isn''t? >> Magnus Holm notes that while JSON is meant to also be syntactically >> legal JavaScript code.. it isn''t always. What has Magnus discovered? >> Find out here. >> >> > http://timelessrepo.com/json-isnt-a-javascript-subset?utm_source=javascriptweekly&utm_medium=email >> >> -Rob > > Hi, thanks. Just don''t see how to use the solution. > I have used the patched rack middleware proposed but the problem > remains. > I guess it looks for U+2028 or U+2029 but I guess they are not present > in my case...But there two other characters and you have BOTH of those: The following characters are consider to be line terminators: • \u000A - Line Feed • \u000D - Carriage Return • \u2028 - Line separator • \u2029 - Paragraph separator Line feed, aka, \n Carriage return, aka, \r You might have to patch the patch to use the Unicode escape for the others, too. -Rob Rob Biedenharn Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org http://AgileConsultingLLC.com/ rab-/VpnD74mH8+00s0LW7PaslaTQe2KTcn/@public.gmane.org http://GaslightSoftware.com/ -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> > But there two other characters and you have BOTH of those: > The following characters are consider to be line terminators: > > \u000A - Line Feed > \u000D - Carriage Return > \u2028 - Line separator > \u2029 - Paragraph separator > > Line feed, aka, \n > Carriage return, aka, \r > > You might have to patch the patch to use the Unicode escape for the > others, too. > > -Rob > > Rob Biedenharn > Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org http://AgileConsultingLLC.com/ > rab-/VpnD74mH8+00s0LW7PaslaTQe2KTcn/@public.gmane.org http://GaslightSoftware.com/Thanks. That is true, I have to check that. I found something interesting with the db configuration files. But I''ll make a new thread not to mix this one. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
comopasta Gr wrote in post #999960:> Hi, > > I''m in trouble with encoding again. > I have a text area. Where I can enter sentences. And when a sentence > that contains multiple lines is typed I get this into the DB: > > (json serialized) > > --- "{\"text\":[\"line one\\r\\nline two\"]}" > > Ok. When I take it from the db I see it like this in the controller: > {"line one\r\nline two"=>"text"} > (I have done something in between to change the order but that''s > irrelevant) > But you can see the \r\n in it. > > The thing is that in the view I need to pass it via javascript to a > function that re-creates the text area dynamically. > > But the function gives the error: "Uncaught SyntaxError: Unexpected > token ILLEGAL"Well now I think I fixed this. Nothing to do with json. More with common sense. Mine. In the controller I just added again the double \ @value = det.last[i].gsub!(/\n/, ''\\n'') @value = det.last[i].gsub!(/\r/, ''\\r'') Then @value can be used in the view and the line breaks stay in place. No JS error and no need to do any CGI::escape to keep them anymore. And no problems with accents since I don''t use CGI::escape anymore. Cheers. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
SOLVED -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.