JavaScript problem with special characters

VERIFIED DUPLICATE of bug 137182

Status

()

Core
DOM: Core & HTML
--
major
VERIFIED DUPLICATE of bug 137182
16 years ago
16 years ago

People

(Reporter: Juarez P. Freitas Jr., Assigned: jst)

Tracking

Trunk
x86
Linux
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(2 attachments, 1 obsolete attachment)

(Reporter)

Description

16 years ago
I have a single page with this javascript code:

...

<td nowrap>

<script language="JavaScript">
function setFKcd_cid(cd_cid, no_cid) {
   objcd_cid = cd_cid;
   objno_cid = no_cid;
}

function getFKcd_cid(cd_cid, no_cid) {
   objcd_cid.value = cd_cid;
   objno_cid.value = no_cid;
   top.newWin.close();
}
</script>

<input type="text" name="cd_cid" value="1" maxlength="5" size="8" tabindex="11"
label="Cidade">
<input type="text" name="no_cid" value="GOIÂNIA" size=40 readonly>
<a href="javascript:doNil()" onclick="setFKcd_cid(document.empForm.cd_cid,
document.empForm.no_cid); top.newWin =
window.open('table_xml.php?filexml=cid_con_fk&FKField=cd_cid','FKcd_cid','dependent=yes,width=550,height=350,screenX=200,screenY=300,titlebar=yes,scrollbars=yes')"><img
src="/img/busca.gif" border="0"></a>

</td>

...

This code starts another page, with the select of values:

...

<tr class="lin1" 
onClick="location.href='javascript:parent.opener.getFKcd_cid(1, \'GOIÂNIA\')'" 
   onMouseOut="style.backgroundColor=''; style.border='0 solid black';" 
   onMouseOver="style.backgroundColor='#FFEA50'; style.cursor='hand';
style.border='0 solid #CCCCCC'">

    <td nowrap >
    &nbsp;GOIÂNIA  </td>
    <td nowrap >
    GO  </td>
    <td nowrap >
    BRASIL  </td>
    <td nowrap >

    74000000  </td>
    <td nowrap >
        </td>
  </tr>
<tr class="lin2" 
onClick="location.href='javascript:parent.opener.getFKcd_cid(2, \'RIO VERDE\')'" 
   onMouseOut="style.backgroundColor=''; style.border='0 solid black';" 
   onMouseOver="style.backgroundColor='#FFEA50'; style.cursor='hand';
style.border='0 solid #CCCCCC'">
    <td nowrap >
    &nbsp;RIO VERDE  </td>
    <td nowrap >

    GO  </td>
    <td nowrap >
    BRASIL  </td>
    <td nowrap >
    75000000  </td>
    <td nowrap >
        </td>

  </tr>
...


If I click in a <TR> with values (2, \'RIO VERDE\'), the event onClick return
this values to the parent page.

If I click in a <TR> with values (1, \'GOIÂNIA\'), the event onClick does not
return anything.

The problem is the &Acirc; on the name GOIÂNIA.

PS.: OK in the Netscape 6.2
     OK in the IE 5.0
     OK in the OPERA

Comment 1

16 years ago
String handling in the browser is handled by the DOM before
the JS Engine. Reassigning to DOM Level 0, and I will attach
a reduced testcase below -
Assignee: rogerl → jst
Component: JavaScript Engine → DOM Level 0
QA Contact: pschwartau → desale
Summary: javascript problem with special characters → JavaScript problem with special characters

Comment 2

16 years ago
Created attachment 86690 [details]
Reduced testcase #1

I'm a bit confused about this: IE6 throws an error when loading this testcase:

			'Invalid character'

It is not the  character that causes this, but rather the backslash 
before the single-quote character:  \'

Once the testcase is loaded, the top row (GOIÂNIA) works fine,
because I didn't use any \' in this row.

But the lower row (RIO VERDE) doesn't work either in Mozilla
nor in IE6, because of the \'

Mozilla never throws an error, either on initial page load
nor on clicking the lower row. You just don't get the expected
alerbox on the onClick event for the row; same as in IE6.

Juarez: have I captured the problem in this testcase? If not, please
attach a reduced testcase via the "Create a New Attachment" link above -

Comment 3

16 years ago
Here is the testcase I attached above:

<script>
function f(x){alert(x);}
</script>


<body>
<p>Click on each table row below </p>

<table>
  <tr onClick="f('GOIÂNIA')">      <td>GOIÂNIA</td>   </tr>
  <tr onClick="f(\'RIO VERDE\')">  <td>RIO VERDE</td> </tr>
</table>


I see why the \' is causing an error in the second row:
although it appears within the double-quotes, the double-quotes
are not "seen" by the JS Engine. The HTML parser is strippping
the double-quotes, as it should.


In the standalone JS shell:

js> var s = "'abc\'"   <--- fine; no error

js> var s = \'abc\';   <--- a bare \' is a syntax error 
6: SyntaxError: illegal character:
6: var s = \'abc\';    


I will obsolete the above testcase and attach a corrected version below -

Updated

16 years ago
Attachment #86690 - Attachment is obsolete: true

Comment 4

16 years ago
Created attachment 86719 [details]
Reduced testcase #1 (corrected)

Comment 5

16 years ago
Here is the new test. It puts the strings into the status bar; 
and I find that Mozilla has no trouble with the special character.
I get no errors in the JavaScript Console.

This makes me think the problem has to do with URL parsing,
since the original HTML above involved putting the special 
character into a URL string...


<script>
function f(x){return x;}
</script>

<body>
<p>Click on each table row below.
</p>

<table>
<tr onClick="window.status='javascript:f(\'GOIÂNIA\')'">  <td>GOIÂNIA </td></tr>
<tr onClick="window.status='javascript:f(\'RIO VERDE\')'"><td>RIOVERDE</td></tr>
</table>

</body>



Juarez, could you attach a reduced testcase that shows the problem?
Thanks -
(Reporter)

Comment 6

16 years ago
Created attachment 86797 [details]
This testcase have the same problem



PS.: I was not tested this problema with IE6, only with IE5.

I was tested with NS6.2, Opera 5 and Konqueror 2.2
(Assignee)

Comment 7

16 years ago
This is all due to our incorrect assumptions about the code in a javascript: URL
always being UTF8, we have other bugs that are due to the same problem...
(Assignee)

Updated

16 years ago
Status: UNCONFIRMED → NEW
Ever confirmed: true

Comment 8

16 years ago
Johny: Which bugs? I am interested as I seem to notice the same on the
JavaScript generated pages of my bank in Poland.
(Assignee)

Comment 9

16 years ago
I was thinking specifically about bug 137182. And this is actually a dupe of
that bug, so duping...

*** This bug has been marked as a duplicate of 137182 ***
Status: NEW → RESOLVED
Last Resolved: 16 years ago
Resolution: --- → DUPLICATE

Comment 10

16 years ago
Verified Duplicate -
Status: RESOLVED → VERIFIED

Comment 11

16 years ago
juarez@saneago.com.br and piskozub@iopan.gda.pl: you are both now 
cc'ed on the duplicate bug 137182 so that you can follow its progress -
You need to log in before you can comment on or make changes to this bug.