From d456663db50629bfb51b88560b01d3ccf13bfdb3 Mon Sep 17 00:00:00 2001 From: Anders Bergh Date: Thu, 19 Jun 2014 16:32:07 +0200 Subject: [PATCH] Replace all non-ASCII bytes with "?" in case of broken UTF-8. --- js/weechat.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/js/weechat.js b/js/weechat.js index bd9870b..c2698fd 100644 --- a/js/weechat.js +++ b/js/weechat.js @@ -579,7 +579,13 @@ decodedString = decodeURIComponent(escape(encodedString)); return decodedString; } catch (exception) { - return "--Sorry, Glowing Bear cannot decode this line as it is invalid--"; + // Replace all non-ASCII bytes with "?" if the string couldn't be + // decoded as UTF-8. + var s = ""; + for (var i = 0, n = uia.length; i < n; i++) { + s += uia[i] < 0x80 ? String.fromCharCode(uia[i]) : "?"; + } + return s; } };