in reply to Re^2: Perl, JavaScript and quoting/escaping
in thread Perl, JavaScript and quoting/escaping

[ Please don't use <pre> here. Start paragraphs with <p>, and wrap computer text (code, input, output, etc) in <c>...</c>. <c>...</c> will even handle escaping "&", "<", ">", "[" and "]" for you. ]

Is there an alternative to text_to_js_lit packaged as a module?

package Module; sub text_to_js_lit { my $s = @_ ? $_[0] : $_; $s =~ s/\\/\\\\/g; $s =~ s/'/\\'/g; # ... return qq{'$s'}; } 1;

I'm surprised that (q{\'\'} eq q{\'\'}); wouldn't this be eq q{''}?

Say again?

Where I was so lost as to why I couldn't get my string to popup. [...] Where the result is not readable, this string is displayed as is.

What? You just said the same piece of code didn't display the message and displayed it as-is.

Replies are listed 'Best First'.
Re^4: Perl, JavaScript and quoting/escaping
by Anonymous Monk on May 06, 2011 at 01:49 UTC
    Haha, lol.
    I'm just not used to the markup of this forum and I can't escape properly.
Re^4: Perl, JavaScript and quoting/escaping
by Anonymous Monk on May 06, 2011 at 01:53 UTC

    qq{\&#39;\&#39;} eq q{&#39;&#39;}

    " VS &quote;

      I'm surprised that (qq{\&#39;\&#39;} eq q{&#39;&#39;}; wouldn't this be eq q{''}?

      Still makes no sense to me.

      " VS &quote;

      So you're asking how to embed double quotes in a JS double-quoted string literal? This isn't really an appropriate place to ask that. One escapes them with a backslash:

      alert("foo \"bar\" baz"); // foo "bar" baz
        For example:
        open(...) or print 'alert("foo '.$!.' baz");';
        If/when $! contains one of '", ect. As the escape-e could be anything and in my case content provided from a insecure variable I need something that can withstand any amount of trickery done by malicious ppl.
Re^4: Perl, JavaScript and quoting/escaping
by Anonymous Monk on May 06, 2011 at 02:08 UTC
    Looking for a CPAN module that's hopefully maintained with a bug tracker. For example there are vary good functions for escaping for URL, HTML, many forms of SQL, ect, ect, ect. Where is the one for JavaScript?