microsoft / microsoft/terminal
Warn if settings.json is not UTF-8 (at least in key binding)
- Dominant language
- C++
- Stars
- 105k
- Forks
- 9.6k
- Avg merge
- 3d 17h
- Merged PRs (30d)
- 29
Description
# Description of the new feature/enhancement
If settings.json is encoded in e.g. Windows-1252 rather than UTF-8, then Terminal should warn about that, rather than silently substitute U+FFFD replacement characters in strings. This would help users who edit settings.json with Visual Studio, which saves in the ANSI code page by default if the file does not appear to be UTF-8 already. The silent substitution is especially hard to diagnose if the only non-ASCII character is in a key binding that then just does not work.
# Proposed technical implementation details (optional)
Apply settings.json as much as possible, but then pop up a message saying that the encoding is wrong.
AFAICT, jsoncpp gives the raw bytes of JSON string values to Terminal if there is are no backslash escapes. These bytes are UTF-8 if the file was correctly encoded. In Terminal, ConversionTrait\::FromJson calls til::u8u16, which calls MultiByteToWideChar without the MB_ERR_INVALID_CHARS flag. There are more til::u8u16 calls in other ConversionTrait specializations.
Contributor guide
Research direction
Start with KeyChordSerialization.cpp, JsonUtils.h, and u8u16convert.h, following the til::u8u16 calls and the MultiByteToWideChar conversion described in the issue. Trace how settings.json bytes reach key bindings and other ConversionTrait specializations. Done means invalid encoding is detected, settings are applied as far as possible, and Terminal shows a warning instead of silently substituting replacement characters.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- desktop
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100