Hex-escape unprintable characters in terminal tab

If there's any binary going over the line like null bytes, we want to
see that here too.
This commit is contained in:
Gina Häußge 2017-02-20 12:05:38 +01:00
parent e1eaf4eb8e
commit 7f0eb8d895
2 changed files with 34 additions and 1 deletions

View file

@ -883,3 +883,36 @@ var getQueryParameterByName = function(name, url) {
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
};
/**
* Escapes unprintable ASCII characters in the provided string.
*
* E.g. turns a null byte in the string into "\x00".
*
* Only characters 0 to 31, 127 and 255 will be escaped, that
* should leave printable characters and unicode alone.
*
* Originally based on
* https://gist.github.com/mathiasbynens/1243213#gistcomment-53590
*
* @param str The string to escape
* @returns {string}
*/
var escapeUnprintableCharacters = function(str) {
var result = "";
var index = 0;
var charCode;
while (!isNaN(charCode = str.charCodeAt(index))) {
if (charCode < 32 || charCode == 127 || charCode == 255) {
// special hex chars
result += "\\x" + (charCode > 15 ? "" : "0") + charCode.toString(16)
} else {
// anything else
result += str[index];
}
index++;
}
return result;
};

View file

@ -201,7 +201,7 @@ $(function() {
if (type == undefined) {
type = "line";
}
return {line: line, type: type}
return {line: escapeUnprintableCharacters(line), type: type}
};
self._processStateData = function(data) {