Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #28811
| From | Stefan Weiss <krewecherl@gmail.com> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: How to pass a php variable to a javascript file (function)? |
| Date | 2015-10-05 01:11 +0200 |
| Organization | albasani.net |
| Message-ID | <musbm7$cd5$1@news.albasani.net> (permalink) |
| References | (1 earlier) <XnsA5276328DD4DEeejj99@194.109.6.166> <mulldu$lli$1@news.albasani.net> <1739227.XXYPReGQTy@PointedEars.de> <mun0p1$d9i$3@news.albasani.net> <13501800.DmYS3OLCIa@PointedEars.de> |
On 2015-10-03 04:35, Thomas 'PointedEars' Lahn wrote:
> Stefan Weiss wrote:
>> I wrote (quoted) that "<script" should be replaced with
>> "<\script".
...
> This assertion is in the same sense wrong as is the following one further
> below the Specification prose, in another note:
[ snip spec note ]
> The problem here is that the authors make the common mistake
> and use the term “JavaScript” as an umbrella term, failing to differentiate
> between ECMAScript implementations.
Oh, here we go again... Don't you ever get tired of this?
>> str_replace("<script", "<\script", $some_text);
>>
>> Done.
>
> No.
...because? A simple unqualified "no" is not good enough.
> (And it is bad practice to use unknown escapes in double-quoted string
> literals in PHP.
"\s" is not an unknown escape, it's two characters. If this offends your
eyes, or you're not sure what is an what isn't an escape sequence in a
PHP string, you're free to use "\\s" or '\s'. The result is the same.
> It is also unwise to use double-quoted string literals
> where single-quoted string literals would have sufficed, because different
> to ECMAScript, double quotes also imply interpolation in PHP [and several
> other script languages].)
Thanks for the lecture, but I'm well aware of how PHP strings work. The
single vs double quote issue has been discussed ad nauseam, and what it
always boils down to is that it's primarily a matter of preference
(which you have a tendency to elevate to laws, for some reason). The
main point is to be consistent.
>> And even *IF* it was a Perl regex (which is a completely random
>> and off-topic assumption), the "\s" is in the replacement part, not in
>> the matching part.
>
> I was talking about code that can be (but does not have to be) contained in
> markup, code that uses regular expressions to match and process markup.
> That code will be broken by blind escaping to accomodate HTML parsers.
Then you're talking about something nobody asked. This is not about
escaping code, it's about escaping the contents of a string in a
<script> element.
> Interesting. As for Chromium 44.0.2403.89 on GNU/Linux, for which I can
> confirm that unescaped “</script>” in a “script” element is a problem, this
> should be considered a bug as (AFAICS) the given ABNF for the “script”
> element content allows “</script>” in it.
It's not just Chrome, you get the exact same behavior in Firefox and
IE/Edge. For once, everyone agrees. There may or may not be an error in
the specification - I only skimmed the quoted ABNF because I'm really
not interested in that. The intention was made well clear in the note
accompanying the formal definition. If there is indeed an error, file a
bug against the specification.
Unescaped "</script>" in a string causes problems, as has been
demonstrated. The problems can be avoided by escaping it as
"<\/script>". This is how it works, and how the specification says it
should work (again, possibly with an error in the details, according to
you).
> I did _not_ say that I think that it is *safe*. I said that it
> is not a problem in those markup languages. Which is correct (in theory).
But not in practice.
>> To get a valid XML document, you'll have to escape much more than the
>> strings I mentioned.
>
> No, as I have said many times before in both in
> <news:de.comp.lang.javascript> and here, you just have to declare the
> offending “script” element content a part of a CDATA section
Then that's a completely different context. You obviously have to use
different escaping in a CDATA section...
> // escape “]]>” here if “<” follows
... but not like that!
> But none of this is necessary, regardless of the document type, if you move
> the “script” element content to a separate file, and use the “src”
> attribute, AISB.
Correct but off-topic.
> If you can’t stand the heat [...blah...] stay out of the kitchen.
There is no heat, there's only you. And despite what you might think,
most of your sermons don't come across as constructive or challenging,
just as tedious and pedantic. My main complaint is that you write in a
very condescending way, all but forcing the other party to write a
rebuttal. This is a tremendous waste of my time.
In other words: I'm avoiding the kitchen for extended periods of time
because it's full of bureaucrats rather than cooks.
Look at this exchange as a perfect illustration. Here we are, at the end
of your very long reply. You blather at length about external script
files, bad practices of writing PHP code, spec authors who don't
subscribe to your "There is no Javascript" philosophy, nitpicks about
the examples in the spec, escaping JS code instead of string contents,
and the HTML5 validator.
And after all that we still have no reason why we shouldn't escape
"</script" as "<\/script", except for a possible error in the
specification. But at least you got to say "No" and call somebody else
wrong.
> IOW: Your logic is flawed. You should learn to control your emotions lest
> they control you.
Somebody's taking their science fiction a little too seriously.
- stefan
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
How to pass a php variable to a javascript file (function)? JiiPee <no@notvalid.com> - 2015-10-02 00:13 +0100
Re: How to pass a php variable to a javascript file (function)? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-10-02 09:44 +0200
Re: How to pass a php variable to a javascript file (function)? Stefan Weiss <krewecherl@gmail.com> - 2015-10-02 12:14 +0200
Re: How to pass a php variable to a javascript file (function)? JiiPee <no@notvalid.com> - 2015-10-02 11:43 +0100
Re: How to pass a php variable to a javascript file (function)? JiiPee <no@notvalid.com> - 2015-10-02 11:58 +0100
Re: How to pass a php variable to a javascript file (function)? Stefan Weiss <krewecherl@gmail.com> - 2015-10-02 13:38 +0200
Re: How to pass a php variable to a javascript file (function)? JiiPee <no@notvalid.com> - 2015-10-02 12:53 +0100
Re: How to pass a php variable to a javascript file (function)? JiiPee <no@notvalid.com> - 2015-10-02 13:46 +0100
Re: How to pass a php variable to a javascript file (function)? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-02 13:51 +0100
Re: How to pass a php variable to a javascript file (function)? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-10-02 21:42 +0200
Re: How to pass a php variable to a javascript file (function)? Stefan Weiss <krewecherl@gmail.com> - 2015-10-03 00:33 +0200
Re: How to pass a php variable to a javascript file (function)? JiiPee <no@notvalid.com> - 2015-10-02 23:45 +0100
Re: How to pass a php variable to a javascript file (function)? Tim Streater <timstreater@greenbee.net> - 2015-10-02 23:55 +0100
Re: How to pass a php variable to a javascript file (function)? JiiPee <no@notvalid.com> - 2015-10-03 00:02 +0100
Re: How to pass a php variable to a javascript file (function)? JiiPee <no@notvalid.com> - 2015-10-02 23:49 +0100
Re: How to pass a php variable to a javascript file (function)? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-10-02 21:37 +0200
Re: How to pass a php variable to a javascript file (function)? Stefan Weiss <krewecherl@gmail.com> - 2015-10-03 00:34 +0200
Re: How to pass a php variable to a javascript file (function)? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-10-03 04:35 +0200
Re: How to pass a php variable to a javascript file (function)? Stefan Weiss <krewecherl@gmail.com> - 2015-10-05 01:11 +0200
Re: How to pass a php variable to a javascript file (function)? Tim Streater <timstreater@greenbee.net> - 2015-10-05 09:13 +0100
Re: How to pass a php variable to a javascript file (function)? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-10-06 03:30 +0200
Re: How to pass a php variable to a javascript file (function)? Stefan Weiss <krewecherl@gmail.com> - 2015-10-10 00:27 +0200
Re: How to pass a php variable to a javascript file (function)? Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2015-10-03 15:15 -0300
Re: How to pass a php variable to a javascript file (function)? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-10-03 20:34 +0200
Re: How to pass a php variable to a javascript file (function)? Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2015-10-03 15:59 -0300
Re: How to pass a php variable to a javascript file (function)? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-10-03 22:15 +0200
Re: How to pass a php variable to a javascript file (function)? JiiPee <no@notvalid.com> - 2015-10-02 11:36 +0100
Re: How to pass a php variable to a javascript file (function)? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-10-02 16:34 +0200
Re: How to pass a php variable to a javascript file (function)? JiiPee <no@notvalid.com> - 2015-10-02 16:00 +0100
Re: How to pass a php variable to a javascript file (function)? Tim Streater <timstreater@greenbee.net> - 2015-10-02 16:03 +0100
Re: How to pass a php variable to a javascript file (function)? JiiPee <no@notvalid.com> - 2015-10-02 17:08 +0100
solution, thanks, seems like one suggestion lead to a solution JiiPee <no@notvalid.com> - 2015-10-02 17:07 +0100
Re: solution, thanks, seems like one suggestion lead to a solution "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-10-02 20:29 +0200
csiph-web