From 0cb500899ef7eef54f672ba13731e392c1e4775a Mon Sep 17 00:00:00 2001 From: Padmamanickam Date: Wed, 31 Aug 2022 21:58:42 +0200 Subject: [PATCH] fix: don't let control characters mess up the display MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before: ╭─ CommandT [file] ────────────────────────────────────────────╮ │> │ ╰──────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────╮ │> │ │↳ Icon^M │ │↳ │ │ brew.rb │ │ ...etc │ ╰──────────────────────────────────────────────────────────────╯ After: ╭─ CommandT [file] ────────────────────────────────────────────╮ │> │ ╰──────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────╮ │> Icon\r │ │ brew.rb │ │ ...etc │ ╰──────────────────────────────────────────────────────────────╯ Note that this is a display-only thing, to stop undesired wrapping and other visual distortions. You can't actually type "Icr" and expect it to match the file (these is no "r" in the name), although you can open it by accepting the selection. Closes: https://github.com/wincent/command-t/issues/402 --- lua/wincent/commandt/private/match_listing.lua | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lua/wincent/commandt/private/match_listing.lua b/lua/wincent/commandt/private/match_listing.lua index 90b4af8..31a8555 100644 --- a/lua/wincent/commandt/private/match_listing.lua +++ b/lua/wincent/commandt/private/match_listing.lua @@ -46,6 +46,16 @@ end local format_line = function(line, width, selected) local prefix = selected and '> ' or ' ' + -- Sanitize some control characters, plus blackslashes. + line = line + :gsub('\\', '\\\\') + :gsub('\b', '\\b') + :gsub('\f', '\\f') + :gsub('\n', '\\n') + :gsub('\r', '\\r') + :gsub('\t', '\\t') + :gsub('\v', '\\v') + -- Right pad so that selection highlighting is shown across full width. if width < 104 then if #line > 99 then