terminal/src
James Holderness 6742965bb8
Disable the acceptance of C1 control codes by default (#11690)
There are some code pages with "unmapped" code points in the C1 range,
which results in them being translated into Unicode C1 control codes,
even though that is not their intended use. To avoid having these
characters triggering unintentional escape sequences, this PR now
disables C1 controls by default.

Switching to ISO-2022 encoding will re-enable them, though, since that
is the most likely scenario in which they would be required. They can
also be explicitly enabled, even in UTF-8 mode, with the `DECAC1` escape
sequence.

What I've done is add a new mode to the `StateMachine` class that
controls whether C1 code points are interpreted as control characters or
not. When disabled, these code points are simply dropped from the
output, similar to the way a `NUL` is interpreted.

This isn't exactly the way they were handled in the v1 console (which I
think replaces them with the font _notdef_ glyph), but it matches the
XTerm behavior, which seems more appropriate considering this is in VT
mode. And it's worth noting that Windows Explorer seems to work the same
way.

As mentioned above, the mode can be enabled by designating the ISO-2022
coding system with a `DOCS` sequence, and it will be disabled again when
UTF-8 is designated. You can also enable it explicitly with a `DECAC1`
sequence (originally this was actually a DEC printer sequence, but it
doesn't seem unreasonable to use it in a terminal).

I've also extended the operations that save and restore "cursor state"
(e.g. `DECSC` and `DECRC`) to include the state of the C1 parser mode,
since it's closely tied to the code page and character sets which are
also saved there. Similarly, when a `DECSTR` sequence resets the code
page and character sets, I've now made it reset the C1 mode as well.

I should note that the new `StateMachine` mode is controlled via a
generic `SetParserMode` method (with a matching API in the `ConGetSet`
interface) to allow for easier addition of other modes in the future.
And I've reimplemented the existing ANSI/VT52 mode in terms of these
generic methods instead of it having to have its own separate APIs.

## Validation Steps Performed

Some of the unit tests for OSC sequences were using a C1 `0x9C` for the
string terminator, which doesn't work by default anymore. Since that's
not a good practice anyway, I thought it best to change those to a
standard 7-bit terminator. However, in tests that were explicitly
validating the C1 controls, I've just enabled the C1 parser mode at the
start of the tests in order to get them working again.

There were also some ANSI mode adapter tests that had to be updated to
account for the fact that it has now been reimplemented in terms of the
`SetParserMode` API.

I've added a new state machine test to validate the changes in behavior
when the C1 parser mode is enabled or disabled. And I've added an
adapter test to verify that the `DesignateCodingSystems` and
`AcceptC1Controls` methods toggle the C1 parser mode as expected.

I've manually verified the test cases in #10069 and #10310 to confirm
that they're no longer triggering control sequences by default.
Although, as I explained above, the C1 code points are completely
dropped from the output rather than displayed as _notdef_ glyphs. I
think this is a reasonable compromise though.

Closes #10069
Closes #10310
2021-11-17 23:40:31 +00:00
..
api-ms-win-core-synch-l1-2-0 Introduce a api-ms-win-core-synch-l1-2-0 shim for Windows 7 (#10559) 2021-07-07 16:48:28 +00:00
buffer Standardize the color table order (#11602) 2021-11-04 22:13:22 +00:00
cascadia Disable the acceptance of C1 control codes by default (#11690) 2021-11-17 23:40:31 +00:00
dep
host Disable the acceptance of C1 control codes by default (#11690) 2021-11-17 23:40:31 +00:00
inc Migrate OSS up to f9b97c488 2021-11-09 13:39:28 -06:00
interactivity Fix missing window border when use "win+arrow down" in fullscreen mode in Conhost (#11692) 2021-11-16 16:14:54 +00:00
internal Implement Default Terminal (#7489) 2021-03-26 17:09:49 -05:00
propsheet Merged PR 6176782: [Git2Git] Get rid of dead build macros/#defines FE_IME, W32_SB, etc. 2021-06-21 10:50:52 -07:00
propslib Introduce AtlasEngine - A new text rendering prototype (#11623) 2021-11-13 00:10:06 +00:00
renderer Use nearby fonts for font fallback (#11764) 2021-11-16 23:22:02 +00:00
server Migrate OSS up to f9a844dbd 2021-09-21 16:22:57 -05:00
staging Merged PR 6147892: Make til::feature build in the OS 2021-06-11 17:57:36 +00:00
terminal Disable the acceptance of C1 control codes by default (#11690) 2021-11-17 23:40:31 +00:00
testlist Reflect testlist change from OS 2021-03-29 15:24:43 -05:00
til Add an enum-compatible bitset class. (#10492) 2021-09-27 13:27:29 +00:00
tools Remove time and sys (#11100) 2021-09-01 21:30:39 +00:00
tsf Fix Touch Keyboard invocation issue (#11389) 2021-10-04 14:29:56 +00:00
types Add a file for storing elevated-only state (#11222) 2021-11-13 01:58:43 +01:00
winconpty Implement and action for manually clearing the Terminal (and conpty) buffer (#10906) 2021-09-02 14:59:42 +00:00
common.build.post.props Add support for branch- and branding-based feature flagging (#10361) 2021-06-10 23:09:52 +00:00
common.build.pre.props Compile OpenConsoleProxy without CRT (#11610) 2021-10-26 19:08:49 +00:00
common.build.tests.props Enable /Zc:preprocessor (#10593) 2021-07-13 23:00:11 +00:00
common.pgo.compile.props Implement PGO in pipelines for AMD64 architecture; supply training test scenarios (#10071) 2021-05-13 21:12:30 +00:00
common.pgo.runtime.props Implement PGO in pipelines for AMD64 architecture; supply training test scenarios (#10071) 2021-05-13 21:12:30 +00:00
ConsolePerf.regions.xml
ConsolePerf.wprp Set keyword flags on all tracelog events (#10098) 2021-05-14 23:14:26 +00:00
cppwinrt.build.post.props Upgrade to C++/WinRT 2.0.210825.3 (#11188) 2021-09-10 21:33:13 +00:00
cppwinrt.build.pre.props Compile OpenConsoleProxy without CRT (#11610) 2021-10-26 19:08:49 +00:00
dirs Merged PR 6147892: Make til::feature build in the OS 2021-06-11 17:57:36 +00:00
features.xml Introduce AtlasEngine - A new text rendering prototype (#11623) 2021-11-13 00:10:06 +00:00
project.inc Merged PR 6654362: [Git2Git] OS build fixes for f9b97c488 2021-11-09 23:16:26 +00:00
project.unittest.inc
StaticAnalysis.ruleset Fix SA for Visual Studio 16.8 (#8551) 2020-12-11 05:04:30 +00:00
Terminal.wprp Add even MORE logging for defterm (#11537) 2021-10-19 13:29:18 -07:00
unit.tests.x64.runsettings
unit.tests.x86.runsettings
wap-common.build.post.props
wap-common.build.pre.props Fix compilation with VS16.10 and later (#10208) 2021-05-26 20:11:38 +00:00