3

Cmder PowerShell 視窗隱形字元地雷與 VSCode 新功能

 1 year ago
source link: https://blog.darkthread.net/blog/invisible-char-again/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Cmder PowerShell 視窗隱形字元地雷與 VSCode 新功能-黑暗執行緒

對,我又踩到隱形字元的坑!

Fig1_637976404643631650.png

同樣是 D:\,一個說目錄不存在,一個說存在是什麼鬼。

將有問題的 "D:" 貼到中文編碼解析工具,茶包立刻現形,是常見的地雷隱形字元 - Zero Width Space 0x200b

Fig2_637976404645462202.png

踩到隱形字元不是新鮮事,怎麼冒出來的比較值得追究。經驗中這類鬼字元多是複製 Word 或 PowerPoint 內容帶過來的,但我這是查程式問題過題遇到,與 Office 軟體完全沾不上邊。回想了一下,路徑是 Cmder 複製來的,莫非...

Fig3_637976404647396549.gif

開啟 Cmder PowerShell 視窗,用滑鼠選取路徑再按滑鼠右鍵貼上可輕易重現問題,D:\ 前方的問號便是無法顯示的 0x200b。測試微軟原生 PowerShell 命名列視窗無此狀況,看起來是 Cmder 獨有的問題。有了這個經驗,下回從 Cmder 複製路徑,就知道要小心了。

講到這個,就不得不為 VSCode 拍拍手!

VSCode 在 1.63 版加入了「隱形 Unicode 字元提示」(Invisible Unicode Highlighting),上面那段程式在 VSCode 裡會像下圖,D:\ 前方會有個空心黃框,滑鼠移上去會說明這裡有個 0x200b 的坑:

Fig4_637976404649260873.png

是不是超貼心? 啊~~ 福氣啦!

and has 2 comments

Comments

Post a comment

Comment
Name Captcha 30 - 8 =

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK