<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>2669</bug_id>
          
          <creation_ts>2006-01-06 14:44:40 +0000</creation_ts>
          <short_desc>URL encoding in JavaScript/PHP</short_desc>
          <delta_ts>2006-01-06 15:38:45 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>Validator</product>
          <component>Parser</component>
          <version>HEAD</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Windows 2000</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>INVALID</resolution>
          
          
          <bug_file_loc>http://bungalan.nl/test.php</bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Willem">info</reporter>
          <assigned_to name="Terje Bless">link</assigned_to>
          
          
          <qa_contact name="qa-dev tracking">www-validator-cvs</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>7672</commentid>
    <comment_count>0</comment_count>
    <who name="Willem">info</who>
    <bug_when>2006-01-06 14:44:40 +0000</bug_when>
    <thetext>Hello,

the following has kept me busy for some time. While validating pages I&apos;ve
noticed a problem with URLs in JavaScript. I&apos;m supposed to encode all &amp; into
&amp;amp; in a page and in &lt;A&gt; tags. The validator requires me to encode strings in
JavaScript also. But this will cause trouble for PHP script.

I&apos;ve created a sample (/simple) page that demonstrates the issue:
----------------------------------------------------------------------
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;
&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Language&quot; content=&quot;en&quot; /&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot; /&gt;
&lt;title&gt;Validator test&lt;/title&gt;
&lt;script language=&quot;JavaScript&quot; type=&quot;text/javascript&quot;&gt;
function openLink() {
window.location.href = &apos;&lt;?php echo $_SERVER[&apos;SCRIPT_NAME&apos;]; ?&gt;?a=1&amp;amp;b=2&apos;;
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;a href=&quot;&lt;?php echo $_SERVER[&apos;SCRIPT_NAME&apos;]; ?&gt;?a=1&amp;amp;b=2&quot;&gt;open via
link&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;
&lt;form method=&quot;post&quot; action=&quot;&lt;?php echo $_SERVER[&apos;SCRIPT_NAME&apos;]; ?&gt;?a=1&amp;amp;b=2&quot;&gt;
&lt;input type=&quot;submit&quot; value=&quot;open via form&quot; /&gt;&lt;br /&gt;&lt;br /&gt;
&lt;/form&gt;
&lt;input type=&quot;button&quot; value=&quot;open via jscript&quot; onclick=&quot;openLink()&quot; /&gt;&lt;br /&gt;&lt;br /&gt;
&lt;pre&gt;&lt;?php
// show submitted vars
var_dump($_REQUEST);
?&gt;&lt;/pre&gt;
&lt;/body&gt;
&lt;/html&gt;
----------------------------------------------------------------------

The link and form methods will correctly output:
array(2) {
  [&quot;a&quot;]=&gt;
  string(1) &quot;1&quot;
  [&quot;b&quot;]=&gt;
  string(1) &quot;2&quot;
}

The JavaScript method however will output:
array(2) {
  [&quot;a&quot;]=&gt;
  string(1) &quot;1&quot;
  [&quot;amp;b&quot;]=&gt;
  string(1) &quot;2&quot;
}

So with the JS method it seems the URL isn&apos;t decoded. I&apos;m wondering what the
problem is...

a) It&apos;s not required to encode JS strings, and the validator incorrectly checks
them;
b) PHP isn&apos;t decoding for some reason;
c) the browser doesn&apos;t handle the string as it should (tested with latest MS IE
and Mozilla FF);
d) I&apos;m all wrong and there is a better way to do what I want.

Would be nice to hear what other people think.


Regards, Willem</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>7674</commentid>
    <comment_count>1</comment_count>
    <who name="Bj">bjoern</who>
    <bug_when>2006-01-06 14:57:57 +0000</bug_when>
    <thetext>Your XHTML is probably parsed as HTML; XHTML and HTML define different 
requirements for parsing &lt;script&gt; elements, in HTML escapes such as &amp;amp; will 
not be decoded, in XHTML they would; use the application/xhtml+xml media type 
for such XHTML documents, external scripts, or one of the &lt;![CDATA[]]&gt; escaping 
methods you&apos;ll find all over the web to solve this. See the www-validator 
mailing list archives for details.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>7677</commentid>
    <comment_count>2</comment_count>
    <who name="Willem">info</who>
    <bug_when>2006-01-06 15:38:45 +0000</bug_when>
    <thetext>Hi,

setting the header did the trick, thanks!

&lt;?php header(&apos;Content-Type: application/xhtml+xml&apos;); ?&gt;

Willem</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>