Bug 786169 - Corrupt non-latin text into debugger; r=msucan

This commit is contained in:
Panos Astithas 2012-09-11 11:40:54 +03:00
parent 45661cd6b6
commit d85c86687c
3 changed files with 28 additions and 3 deletions

View File

@ -1272,6 +1272,7 @@ SourceScripts.prototype = {
return self._logError(url, aStatus);
}
let source = NetUtil.readInputStreamToString(aStream, aStream.available());
source = self._convertToUnicode(source);
self._onLoadSourceFinished(url, source, null, options);
aStream.close();
});
@ -1296,8 +1297,8 @@ SourceScripts.prototype = {
if (!Components.isSuccessCode(aStatusCode)) {
return self._logError(url, aStatusCode);
}
self._onLoadSourceFinished(
url, chunks.join(""), channel.contentType, options);
let source = self._convertToUnicode(chunks.join(""), channel.contentCharset);
self._onLoadSourceFinished(url, source, channel.contentType, options);
}
};
@ -1307,6 +1308,28 @@ SourceScripts.prototype = {
}
},
/**
* Convert a given string, encoded in a given character set, to unicode.
* @param string aString
* A string.
* @param string aCharset
* A character set.
* @return string
* A unicode string.
*/
_convertToUnicode: function SS__convertToUnicode(aString, aCharset) {
// Decoding primitives.
let converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"]
.createInstance(Ci.nsIScriptableUnicodeConverter);
try {
converter.charset = aCharset || "UTF-8";
return converter.ConvertToUnicode(aString);
} catch(e) {
return aString;
}
},
/**
* Called when a script's source has been loaded.
*

View File

@ -70,6 +70,8 @@ function test()
isnot(editor.getText().indexOf("debugger"), -1,
"The correct script was loaded initially.");
isnot(editor.getText().indexOf("\u263a"), -1,
"Unicode characters are converted correctly.");
contextMenu = gDebugger.document.getElementById("sourceEditorContextMenu");
ok(contextMenu, "source editor context menupopup");

View File

@ -2,6 +2,6 @@
http://creativecommons.org/publicdomain/zero/1.0/ */
function secondCall() {
// This comment is useful for browser_dbg_select-line.js.
// This comment is useful for browser_dbg_select-line.js.
eval("debugger;");
}