W3C home > Mailing lists > Public > www-validator-cvs@w3.org > January 2006

[Bug 2669] URL encoding in JavaScript/PHP

From: <bugzilla@wiggum.w3.org>
Date: Fri, 06 Jan 2006 14:45:10 +0000
To: www-validator-cvs@w3.org
Message-Id: <E1Eusq6-00012J-2T@wiggum.w3.org>


           Summary: URL encoding in JavaScript/PHP
           Product: Validator
           Version: HEAD
          Platform: PC
               URL: http://bungalan.nl/test.php
        OS/Version: Windows 2000
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Parser
        AssignedTo: link@pobox.com
        ReportedBy: info@megaman.nl
         QAContact: www-validator-cvs@w3.org


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

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

The link and form methods will correctly output:
array(2) {
  string(1) "1"
  string(1) "2"

The JavaScript method however will output:
array(2) {
  string(1) "1"
  string(1) "2"

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

a) It's not required to encode JS strings, and the validator incorrectly checks
b) PHP isn't decoding for some reason;
c) the browser doesn't handle the string as it should (tested with latest MS IE
and Mozilla FF);
d) I'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
Received on Friday, 6 January 2006 14:45:26 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 23:02:15 UTC