Get form data from webdialogs?
-
OK how about 'newline' ?
$("select option;selected").each(function () { str += $(this).text() + "\n"; });then in Ruby
chosen=str.split("\n")?
Or even \r or \f ? -
That would be even more unlikely to appear, but it's still possible - for instance the Ruby API will allow
\n. Who knows what an importer for instance might put in there when importing from some random data. Or if it takes input from somewhere without sanitising.I mean, it's unlikely, but still possible. Where as using an escape character scheme would make it 100% safe. And it's a simple thing as well.
<span class="syntaxdefault">def escape_pipe</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> string </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> string</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">gsub</span><span class="syntaxkeyword">(</span><span class="syntaxstring">'\\'</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> </span><span class="syntaxstring">'\\\\'</span><span class="syntaxkeyword">).</span><span class="syntaxdefault">gsub</span><span class="syntaxkeyword">(</span><span class="syntaxstring">'|'</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> </span><span class="syntaxstring">'\\|'</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">end<br /><br />def restore_pipe</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> string </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> string</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">gsub</span><span class="syntaxkeyword">(</span><span class="syntaxstring">'\\\\'</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> </span><span class="syntaxstring">'\\'</span><span class="syntaxkeyword">).</span><span class="syntaxdefault">string</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">gsub</span><span class="syntaxkeyword">(</span><span class="syntaxstring">'\\|'</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> </span><span class="syntaxstring">'|'</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault">end<br /></span> -
so far there is no elegant solution for it!
Javascript may be useful but have problem when handling mutibyte characters -
@bigcatln said:
so far there is no elegant solution for it!
Javascript may be useful but have problem when handling mutibyte charactersEh? Javascript is unicode compatible... Ruby on the other hand, the 1.8 branch we're stuck with in SU, only deal with strings as ASCII characters.
-
The problem is JSON doen't support Multibyte characters in fact. when you restore Json str from javascript in ruby,it can't be handled correctly
-
@bigcatln said:
The problem is JSON doen't support Multibyte characters in fact. when you restore Json str from javascript in ruby,it can't be handled correctly
But that's a problem with Ruby 1.8 which only handle ASCII strings - and not a problem with JavaScript...
-
I always do as chris does:
collect in one string, send to SU, split there if needed
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register LoginAdvertisement