<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: Regular Javascript Expressions</title>
	<atom:link href="http://mattmecham.wordpress.com/2006/08/03/regular-javascript-expressions/feed/" rel="self" type="application/rss+xml" />
	<link>http://mattmecham.wordpress.com/2006/08/03/regular-javascript-expressions/</link>
	<description>Matt Mecham's Personal Blog</description>
	<lastBuildDate>Wed, 24 Dec 2008 12:20:48 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Matt</title>
		<link>http://mattmecham.wordpress.com/2006/08/03/regular-javascript-expressions/#comment-2228</link>
		<dc:creator>Matt</dc:creator>
		<pubDate>Wed, 23 Aug 2006 09:57:08 +0000</pubDate>
		<guid isPermaLink="false">http://mattmecham.wordpress.com/2006/08/03/regular-javascript-expressions/#comment-2228</guid>
		<description>Er. Ok.
</description>
		<content:encoded><![CDATA[<p>Er. Ok.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: a</title>
		<link>http://mattmecham.wordpress.com/2006/08/03/regular-javascript-expressions/#comment-2227</link>
		<dc:creator>a</dc:creator>
		<pubDate>Sat, 19 Aug 2006 21:28:12 +0000</pubDate>
		<guid isPermaLink="false">http://mattmecham.wordpress.com/2006/08/03/regular-javascript-expressions/#comment-2227</guid>
		<description>Post something new, for once...</description>
		<content:encoded><![CDATA[<p>Post something new, for once&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rikki</title>
		<link>http://mattmecham.wordpress.com/2006/08/03/regular-javascript-expressions/#comment-2226</link>
		<dc:creator>Rikki</dc:creator>
		<pubDate>Tue, 08 Aug 2006 22:32:09 +0000</pubDate>
		<guid isPermaLink="false">http://mattmecham.wordpress.com/2006/08/03/regular-javascript-expressions/#comment-2226</guid>
		<description>Le Phantom,

If I remember correctly, IE will not execute a script that is &#039;imported&#039; by using the DOM to create it :)</description>
		<content:encoded><![CDATA[<p>Le Phantom,</p>
<p>If I remember correctly, IE will not execute a script that is &#8216;imported&#8217; by using the DOM to create it <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Le Phantom</title>
		<link>http://mattmecham.wordpress.com/2006/08/03/regular-javascript-expressions/#comment-2225</link>
		<dc:creator>Le Phantom</dc:creator>
		<pubDate>Mon, 07 Aug 2006 12:13:16 +0000</pubDate>
		<guid isPermaLink="false">http://mattmecham.wordpress.com/2006/08/03/regular-javascript-expressions/#comment-2225</guid>
		<description>My initial thought: NO! PLEASE DON&#039;T DO THAT!

Because even though your focus is on the javascript regexp,
I can&#039;t but notice that you&#039;re XHR-ing a document with a
script tag, and parse it to extract and execute the javascript.

I&#039;m using your forum software for a (pretty big gaming) hobby
site, but I&#039;m also doing (core) quality assurance for a browser
company, and one of my responsibilities is javascript.

And so my second thought was: NO! PLEASE DON&#039;T DO THAT!

- If you want to **load pages** into your webpage, use iframes.
- If you want to include scripts, then include the script.

I can&#039;t really see any good use cases where you&#039;d want to XHR
a document, and have it&#039;s javascript execute. XHR is for loading
new data, not new business logic.

And was it Rasmus that said about php &quot;when eval() is the answer,
you&#039;re asking the wrong question&quot;? Anyway, it pretty much holds
for javascript as well.

If you load a page from your own server, then you should be able
to split the data into nicely separated entities, and serve them
to your XHR script using xml (and CDATA).

If you&#039;re loading a page from a server you&#039;r not controlling, you&#039;re
open wide to a wide range of XSS attacks, which is really, really bad.

*** Slightly off topic ***
And come to think of it, that&#039;s just as bad as allowing html, xml and
css uploads to IPB by default. You really should not! Most forum admins
have noe idea what XSS is, and will not think of disabling html attachments.
But allowing them is that same as giving any user with upload rights the
ability to highjack any other users&#039; accounts, by having them viewing the
attachment.

It&#039;s also good practice to store your uploads on a different domain than
the one serving the content. Luckily IPB supports that with it&#039;s &quot;Upload URL&quot;
setting. But again, most people don&#039;t know anything about XSS, and why
they should do this. And most people don&#039;t have full control of multiple domains
to play around with either. So uploading anything that is executed by the
browser, that may contain javascript, is a bad thing to have as an &quot;opt out&quot;.
It should be an &quot;opt in&quot;.

This should also have been properly explained in ACP by my taste.
*** Back on topic ***

Anyway, if you really want to load scripts using XHR, and eval them,
the least thing you should do, is to serve them as XML, so you don&#039;t
need to parse the document for script tags.

This is a small example of how to import a script during runtime:

test.html:
&lt;!DOCTYPE&#160;html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;script&#160;type=&quot;text/javascript&quot;&gt;
document.onload&#160;=&#160;function()&#160;{
&#160;&#160;&#160;var&#160;s&#160;=&#160;document.createElement(&#039;script&#039;);
&#160;&#160;&#160;s.setAttribute(&#039;type&#039;,&#039;text/javascript&#039;);
&#160;&#160;&#160;s.setAttribute(&#039;src&#039;,&#160;&#039;imported.js&#039;);
&#160;&#160;&#160;document.body.appendChild(s);
&#160;&#160;&#160;helloWorld();
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;/body&gt;
&lt;/html&gt;

imported.js:
/*&#160;Run&#160;automatically&#160;at&#160;import:&#160;*/
(function()&#160;{
&#160;&#160;&#160;var&#160;div&#160;=&#160;document.createElement(&#039;div&#039;);
&#160;&#160;&#160;div.appendChild(document.createTextNode(&#039;External&#160;javascript&#160;imported.&#039;));
&#160;&#160;&#160;document.body.appendChild(div);
})()

/*&#160;Run&#160;when&#160;called:&#160;*/
function&#160;helloWorld()&#160;{
&#160;&#160;&#160;var&#160;div&#160;=&#160;document.createElement(&#039;div&#039;);
&#160;&#160;&#160;div.appendChild(document.createTextNode(&#039;Function&#160;in&#160;imported&#160;javascript&#160;ran.&#039;));
&#160;&#160;&#160;document.body.appendChild(div);
}

The script &quot;imported.js&quot; could of course be dynamically generated based
on a query string, so you could use just one javascript serving script
to generate all your &quot;run time imported&quot; javascript code.

Wow, this became much longer than anticipated. Oh well, hard drives and bandwidth are cheap these days :-D</description>
		<content:encoded><![CDATA[<p>My initial thought: NO! PLEASE DON&#8217;T DO THAT!</p>
<p>Because even though your focus is on the javascript regexp,<br />
I can&#8217;t but notice that you&#8217;re XHR-ing a document with a<br />
script tag, and parse it to extract and execute the javascript.</p>
<p>I&#8217;m using your forum software for a (pretty big gaming) hobby<br />
site, but I&#8217;m also doing (core) quality assurance for a browser<br />
company, and one of my responsibilities is javascript.</p>
<p>And so my second thought was: NO! PLEASE DON&#8217;T DO THAT!</p>
<p>- If you want to **load pages** into your webpage, use iframes.<br />
- If you want to include scripts, then include the script.</p>
<p>I can&#8217;t really see any good use cases where you&#8217;d want to XHR<br />
a document, and have it&#8217;s javascript execute. XHR is for loading<br />
new data, not new business logic.</p>
<p>And was it Rasmus that said about php &#8220;when eval() is the answer,<br />
you&#8217;re asking the wrong question&#8221;? Anyway, it pretty much holds<br />
for javascript as well.</p>
<p>If you load a page from your own server, then you should be able<br />
to split the data into nicely separated entities, and serve them<br />
to your XHR script using xml (and CDATA).</p>
<p>If you&#8217;re loading a page from a server you&#8217;r not controlling, you&#8217;re<br />
open wide to a wide range of XSS attacks, which is really, really bad.</p>
<p>*** Slightly off topic ***<br />
And come to think of it, that&#8217;s just as bad as allowing html, xml and<br />
css uploads to IPB by default. You really should not! Most forum admins<br />
have noe idea what XSS is, and will not think of disabling html attachments.<br />
But allowing them is that same as giving any user with upload rights the<br />
ability to highjack any other users&#8217; accounts, by having them viewing the<br />
attachment.</p>
<p>It&#8217;s also good practice to store your uploads on a different domain than<br />
the one serving the content. Luckily IPB supports that with it&#8217;s &#8220;Upload URL&#8221;<br />
setting. But again, most people don&#8217;t know anything about XSS, and why<br />
they should do this. And most people don&#8217;t have full control of multiple domains<br />
to play around with either. So uploading anything that is executed by the<br />
browser, that may contain javascript, is a bad thing to have as an &#8220;opt out&#8221;.<br />
It should be an &#8220;opt in&#8221;.</p>
<p>This should also have been properly explained in ACP by my taste.<br />
*** Back on topic ***</p>
<p>Anyway, if you really want to load scripts using XHR, and eval them,<br />
the least thing you should do, is to serve them as XML, so you don&#8217;t<br />
need to parse the document for script tags.</p>
<p>This is a small example of how to import a script during runtime:</p>
<p>test.html:<br />
&lt;!DOCTYPE&nbsp;html&gt;<br />
&lt;html&gt;<br />
&lt;head&gt;<br />
&lt;script&nbsp;type=&#8221;text/javascript&#8221;&gt;<br />
document.onload&nbsp;=&nbsp;function()&nbsp;{<br />
&nbsp;&nbsp;&nbsp;var&nbsp;s&nbsp;=&nbsp;document.createElement(&#8217;script&#8217;);<br />
&nbsp;&nbsp;&nbsp;s.setAttribute(&#8216;type&#8217;,'text/javascript&#8217;);<br />
&nbsp;&nbsp;&nbsp;s.setAttribute(&#8217;src&#8217;,&nbsp;&#8217;imported.js&#8217;);<br />
&nbsp;&nbsp;&nbsp;document.body.appendChild(s);<br />
&nbsp;&nbsp;&nbsp;helloWorld();<br />
}<br />
&lt;/script&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;</p>
<p>&lt;/body&gt;<br />
&lt;/html&gt;</p>
<p>imported.js:<br />
/*&nbsp;Run&nbsp;automatically&nbsp;at&nbsp;import:&nbsp;*/<br />
(function()&nbsp;{<br />
&nbsp;&nbsp;&nbsp;var&nbsp;div&nbsp;=&nbsp;document.createElement(&#8216;div&#8217;);<br />
&nbsp;&nbsp;&nbsp;div.appendChild(document.createTextNode(&#8216;External&nbsp;javascript&nbsp;imported.&#8217;));<br />
&nbsp;&nbsp;&nbsp;document.body.appendChild(div);<br />
})()</p>
<p>/*&nbsp;Run&nbsp;when&nbsp;called:&nbsp;*/<br />
function&nbsp;helloWorld()&nbsp;{<br />
&nbsp;&nbsp;&nbsp;var&nbsp;div&nbsp;=&nbsp;document.createElement(&#8216;div&#8217;);<br />
&nbsp;&nbsp;&nbsp;div.appendChild(document.createTextNode(&#8216;Function&nbsp;in&nbsp;imported&nbsp;javascript&nbsp;ran.&#8217;));<br />
&nbsp;&nbsp;&nbsp;document.body.appendChild(div);<br />
}</p>
<p>The script &#8220;imported.js&#8221; could of course be dynamically generated based<br />
on a query string, so you could use just one javascript serving script<br />
to generate all your &#8220;run time imported&#8221; javascript code.</p>
<p>Wow, this became much longer than anticipated. Oh well, hard drives and bandwidth are cheap these days <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':-D' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jack Chapple</title>
		<link>http://mattmecham.wordpress.com/2006/08/03/regular-javascript-expressions/#comment-2224</link>
		<dc:creator>Jack Chapple</dc:creator>
		<pubDate>Sun, 06 Aug 2006 00:42:02 +0000</pubDate>
		<guid isPermaLink="false">http://mattmecham.wordpress.com/2006/08/03/regular-javascript-expressions/#comment-2224</guid>
		<description>Prototype is for cheating script kiddies :P</description>
		<content:encoded><![CDATA[<p>Prototype is for cheating script kiddies <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt Tavares</title>
		<link>http://mattmecham.wordpress.com/2006/08/03/regular-javascript-expressions/#comment-2223</link>
		<dc:creator>Matt Tavares</dc:creator>
		<pubDate>Sat, 05 Aug 2006 22:36:49 +0000</pubDate>
		<guid isPermaLink="false">http://mattmecham.wordpress.com/2006/08/03/regular-javascript-expressions/#comment-2223</guid>
		<description>one word, prototype (http://prototype.conio.net/)</description>
		<content:encoded><![CDATA[<p>one word, prototype (<a href="http://prototype.conio.net/" rel="nofollow">http://prototype.conio.net/</a>)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris Boulton</title>
		<link>http://mattmecham.wordpress.com/2006/08/03/regular-javascript-expressions/#comment-2222</link>
		<dc:creator>Chris Boulton</dc:creator>
		<pubDate>Sat, 05 Aug 2006 12:25:30 +0000</pubDate>
		<guid isPermaLink="false">http://mattmecham.wordpress.com/2006/08/03/regular-javascript-expressions/#comment-2222</guid>
		<description>Peter/Matt:

The &quot;s&quot; modifier will treat the string as a single line and thus matches new line characters when using &quot;.&quot; too.</description>
		<content:encoded><![CDATA[<p>Peter/Matt:</p>
<p>The &#8220;s&#8221; modifier will treat the string as a single line and thus matches new line characters when using &#8220;.&#8221; too.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter</title>
		<link>http://mattmecham.wordpress.com/2006/08/03/regular-javascript-expressions/#comment-2221</link>
		<dc:creator>Peter</dc:creator>
		<pubDate>Sat, 05 Aug 2006 00:04:07 +0000</pubDate>
		<guid isPermaLink="false">http://mattmecham.wordpress.com/2006/08/03/regular-javascript-expressions/#comment-2221</guid>
		<description>Philip,

You are correct, there is a multiline modifier which is &quot;m&quot; :)


Not sure if my other comment got through, I keep getting an error &quot;No entry_id&quot;.</description>
		<content:encoded><![CDATA[<p>Philip,</p>
<p>You are correct, there is a multiline modifier which is &#8220;m&#8221; <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Not sure if my other comment got through, I keep getting an error &#8220;No entry_id&#8221;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James</title>
		<link>http://mattmecham.wordpress.com/2006/08/03/regular-javascript-expressions/#comment-2220</link>
		<dc:creator>James</dc:creator>
		<pubDate>Fri, 04 Aug 2006 23:58:12 +0000</pubDate>
		<guid isPermaLink="false">http://mattmecham.wordpress.com/2006/08/03/regular-javascript-expressions/#comment-2220</guid>
		<description>I hate regular expressions, they&#039;re just so messy and easy to break :(</description>
		<content:encoded><![CDATA[<p>I hate regular expressions, they&#8217;re just so messy and easy to break <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Philip Withnall</title>
		<link>http://mattmecham.wordpress.com/2006/08/03/regular-javascript-expressions/#comment-2219</link>
		<dc:creator>Philip Withnall</dc:creator>
		<pubDate>Fri, 04 Aug 2006 20:25:23 +0000</pubDate>
		<guid isPermaLink="false">http://mattmecham.wordpress.com/2006/08/03/regular-javascript-expressions/#comment-2219</guid>
		<description>I don&#039;t know if it&#039;s the same in JS, but there&#039;s a regexp modifier to match across newlines.

I can&#039;t quite remember which one it is, but looking briefly at some of my code tells me it&#039;s either &quot;s&quot; or &quot;m&quot;. :-)</description>
		<content:encoded><![CDATA[<p>I don&#8217;t know if it&#8217;s the same in JS, but there&#8217;s a regexp modifier to match across newlines.</p>
<p>I can&#8217;t quite remember which one it is, but looking briefly at some of my code tells me it&#8217;s either &#8220;s&#8221; or &#8220;m&#8221;. <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
</channel>
</rss>
