Closed
Bug 63626
Opened 25 years ago
Closed 25 years ago
Charset decoding silently fails for JavaScript files.
Categories
(Core :: Internationalization, defect, P5)
Tracking
()
VERIFIED
DUPLICATE
of bug 103954
Future
People
(Reporter: baldauf--2015--bugzilla.mozilla.org, Assigned: nhottanscp)
References
()
Details
(Keywords: intl)
From Bugzilla Helper:
User-Agent: Mozilla/4.76 [en] (Win98; U)
BuildID: 2000122020
Hello,
please check out (using a recent mozilla) following pages:
http://justchat4.medium.net:4000/chat/test/JavaScriptNonASCIITest.latin1.html
and
http://justchat4.medium.net:4000/chat/test/JavaScriptNonASCIITest.utf8.html
Both pages include a javascript file using:
<SCRIPT LANGUAGE="JavaScript" SRC="JavaScriptNonASCIITest.js"></SCRIPT>
. The javascript part of the second page is not executed.
Reproducible: Always
Steps to Reproduce:
1. Make a HTML page be returned as UTF-8 by your web server
2. Let this HTML page reference a javascript page whose contents are to be
executed.
3. Let the javascript page contain some Latin-1 but not ASCII-characters like a
german umlaut "ä" Such a character should be enclosed in a javascript comment
("/* ... */" or "// ... \n")
Actual Results: The contents of the javascript page never will be executed.
Expected Results: The contents of the javascript page should be executed.
It's very hard to track down this bug, as you never would expect your comments
to be the reason for the not-executing of your exported javascript.
The actual bug seems to be that for the .js-file, the same encoding as the
calling page is assumed. IMHO this is a wrong assumption, because JavaScript
source code is defined to be of latin-1.
Even if you assume that your .js-file is of UTF-8, it is a bug that if there is
a character encoding error encountered, this condition is not reported.
It is an additional bug that even if the there is that character encoding error
condition, the rest of the calling page is not displayed, even when the text to
be displayed comes before the
<SCRIPT LANGUAGE="JavaScript" SRC="JavaScriptNonASCIITest.js"></SCRIPT> section.
Solutions:
At least either
- always assume latin1 for .js-files or
- report charset conversion errors
Once you know what's going on, fixing the .js-files is fairly easy. But the way
to know how it is is extremely long... :-(
Comment 1•25 years ago
|
||
Confirming with Linux and WinNT Mozilla binaries 20001221xx.
Changing OS to "All".
Not JS Engine; reassigning to Internationalization for further triage -
Assignee: rogerl → nhotta
Status: UNCONFIRMED → NEW
Component: Javascript Engine → Internationalization
Ever confirmed: true
OS: Windows 98 → All
QA Contact: pschwartau → teruko
| Assignee | ||
Comment 2•25 years ago
|
||
>- always assume latin1 for .js-files or
>- report charset conversion errors
The requests above are for not the charset converter but the client of the
charset converter, so that's JS in this case.
But i18n need to decide if we want to change the current behavior, 4.x has the
same behavior as 6.0. Cc to some i18n people, is there a way to specify charset
(e.g. content-type of script tag)?
Comment 4•25 years ago
|
||
> But i18n need to decide if we want to change the current
> behavior, 4.x has the same behavior as 6.0. Cc to some
> i18n people, is there a way to specify charset
> (e.g. content-type of script tag)?
The SCRIPT tag should be able to take 'charset'
attribute for the SRC file according to HTML 4.x.
So, the answer is yes. If we are not honoring the
charset attribute for the source, then it needs to be
fixed.
Another factor to consider is that if a JS file is
signed, it should use only escaped characters
for the 8-bit portion of the text since conversion of
any kind will invalidate the signature.
Can the reporter of the bug point to an official
document that says that the source file must be
in iso-8859-1?
Comment 5•25 years ago
|
||
Ways to control the character set of the JS file:
'charset' attribute on the 'Content-Type' HTTP header
'charset' parameter on the 'type' attribute
'charset' attribute
There may be others. The higher on the list, the higher the priority.
This is what ECMA-262 has to say about this issue:
# 6. Source Text
# ECMAScript source text is represented as a sequence of characters in the
# Unicode character encoding, version 2.1 or later, using the UTF-16
# transformation format. The text is expected to have been normalised to
# Unicode Normalised Form C (canonical composition), as described in Unicode
# Technical Report #15. Conforming ECMAScript implementations are not required
# to perform any normalisation of text, or behave as though they were
# performing normalisation of text, themselves.
#
# SourceCharacter ::
# any Unicode character
#
# ECMAScript source text can contain any of the Unicode characters. All Unicode
# white space characters are treated as white space, and all Unicode
# line/paragraph separators are treated as line separators. Non-Latin
# Unicode characters are allowed in identifiers, string literals, regular
# expression literals and comments.
Therefore it seems to me that we should definitely not be using the source
document's character set in decoding JS files, we should simply always assume
them to be in UTF-16 regardless of any charset attributes or parameters.
Back to JS engine?
| Reporter | ||
Comment 6•25 years ago
|
||
Okay, I again looked at the docs. JavaScript source code is not required to be
of Latin-1, ftp://ftp.ecma.ch/ecma-st/Ecma-262.pdf (The ECMA-Script-Standard)
page 10 (pdf-page 22) states.
"ECMAScript source text is represented as a sequence of characters in the
Unicode character encoding, version 2.1 or later, using the UTF-16
transformation format." So that's the internal representation, I suppose, as it
should not be the only external one, as there is a large base of JavaScript
consisting of Latin-1 characters out there.
I had been coming to the conclusion that JavaScript source code has to be of
Latin-1, because some docs (http://www.teamone.de/selfhtml/tecl.htm#a8 only in
german) told me that String.charCodeAt() actually returns a Latin-1 code point.
That led me to the conclusion that JavaScript-Strings are purely of Latin-1 code
, so the source code (also describing the content of the string) cannot be a
superset of Latin-1, because there would be the problem how to map non
Latin-1-characters to Latin-1-strings.
I was wrong, as both the standards and also netscape docs at
http://developer.netscape.com/docs/manuals/js/client/jsref/string.htm tell.
Nevertheless, an error message when encountering a decoding-error, would be
fine.
Comment 7•25 years ago
|
||
I guess the code which ignore the error is in the follwoing palce(Not 100%
sure). in mozilla/layout/html/document/src/nsHTMLContentSink.cpp
4689 valeski 3.301 HTMLContentSink::OnStreamComplete(nsIStreamLoader* aLoader,
4690 nsISupports* aContext,
4691 nsresult aStatus,
4692 PRUint32 stringLen,
4693 const char* string)
...
4763 jbetak 3.328 rv = charsetConv->GetUnicodeDecoder(&characterSet,
4764 getter_AddRefs(unicodeDecoder));
4765 NS_RELEASE(charsetConv);
4766 }
4767
4768 // converts from the charset to unicode
4769 if (NS_SUCCEEDED(rv)) {
4770 rv = unicodeDecoder->GetMaxLength(string,
stringLen, &unicodeLength);
4771 if (NS_SUCCEEDED(rv)) {
4772 mUnicodeXferBuf.SetCapacity(unicodeLength);
4773 unicodeString = (PRUnichar *)
mUnicodeXferBuf.GetUnicode();
4774 rv = unicodeDecoder->Convert(string, (PRInt32
*) &stringLen, unicodeString, &unicodeLength);
4775 if (NS_SUCCEEDED(rv)) {
4776 mUnicodeXferBuf.SetLength(unicodeLength);
4777 } else {
4778 jbetak 3.335 mUnicodeXferBuf.SetLength(0);
4779 jbetak 3.328 }
4780 }
4781 }
it seems in the case of error, we will call
mUnicodeXferBuf.SetLength(0);
which make the JavaScript as empty. nhotta, can you help to fix this? we
probably should do a better error handling in this case, what error code should
re return ?
Set to P3
Comment 8•25 years ago
|
||
low priority. Mark it as Future
Priority: P3 → P5
Target Milestone: --- → Future
| Assignee | ||
Updated•25 years ago
|
Status: NEW → ASSIGNED
Comment 9•25 years ago
|
||
*** Bug 104209 has been marked as a duplicate of this bug. ***
Comment 10•25 years ago
|
||
In bug 104209, Ricardo.Capurro@mail.com notes:
If I create a file xx.js with this content
alert('Processing xx.js');
// ó
Note that the comment has an accented ó and I include this file
in the HTML with
<script language="JavaScript" src="xx.js"/>
The alert message never happens. If I change the ó for an o,
everything works fine
Comment 11•25 years ago
|
||
may related to 103945.
Comment 12•25 years ago
|
||
sorry, not bug 103945, it is bug 103954
| Assignee | ||
Comment 13•25 years ago
|
||
*** This bug has been marked as a duplicate of 103954 ***
Status: ASSIGNED → RESOLVED
Closed: 25 years ago
Resolution: --- → DUPLICATE
You need to log in
before you can comment on or make changes to this bug.
Description
•