From b45e52ae71576aea920ab617aaee61a8a477b4f2 Mon Sep 17 00:00:00 2001 From: Allan Odgaard Date: Mon, 7 Oct 2013 18:38:16 +0200 Subject: [PATCH] Remove non-UTF-8 from command output Previously we would create a hex dump from the output. --- Frameworks/editor/src/editor.cc | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Frameworks/editor/src/editor.cc b/Frameworks/editor/src/editor.cc index 821432b0..2fc38c3b 100644 --- a/Frameworks/editor/src/editor.cc +++ b/Frameworks/editor/src/editor.cc @@ -47,6 +47,12 @@ namespace ng return editor->second; } + std::string sanitized_utf8 (std::string str) + { + str.erase(utf8::remove_malformed(str.begin(), str.end()), str.end()); + return str; + } + static find::options_t convert (std::map const& options) { static struct { std::string key; find::options_t flag; } const map[] = @@ -406,9 +412,7 @@ namespace ng unlink(scriptPath.c_str()); std::string const& res = WIFEXITED(status) && WEXITSTATUS(status) == 0 ? output : error; - if(!utf8::is_valid(res.begin(), res.end())) - return text::to_hex(res.begin(), res.end()); - return res; + return utf8::is_valid(res.begin(), res.end()) ? res : sanitized_utf8(res); } } callback; @@ -1303,7 +1307,7 @@ namespace ng bool editor_t::handle_result (std::string const& uncheckedOut, output::type placement, output_format::type format, output_caret::type outputCaret, text::range_t input_range, std::map environment) { - std::string const& out = utf8::is_valid(uncheckedOut.begin(), uncheckedOut.end()) ? uncheckedOut : text::to_hex(uncheckedOut.begin(), uncheckedOut.end()); + std::string const& out = utf8::is_valid(uncheckedOut.begin(), uncheckedOut.end()) ? uncheckedOut : sanitized_utf8(uncheckedOut); range_t range; switch(placement)