terminal/src/host
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
..
exe Introduce AtlasEngine - A new text rendering prototype (#11623) 2021-11-13 00:10:06 +00:00
ft_fuzzer Introduce AtlasEngine - A new text rendering prototype (#11623) 2021-11-13 00:10:06 +00:00
ft_host Introduce AtlasEngine - A new text rendering prototype (#11623) 2021-11-13 00:10:06 +00:00
ft_integrity Fix a bunch of spelling errors across the project (#4295) 2020-02-10 20:40:01 +00:00
ft_uia Enable /Zc:preprocessor (#10593) 2021-07-13 23:00:11 +00:00
lib Standardize the color table order (#11602) 2021-11-04 22:13:22 +00:00
proxy Fix OpenConsoleProxy for Debug builds (#11632) 2021-10-27 19:59:28 +02:00
ut_host Disable the acceptance of C1 control codes by default (#11690) 2021-11-17 23:40:31 +00:00
ut_lib Unify and clean up the common build properties (#3429) 2019-11-05 14:29:11 -08:00
_output.cpp Skip accessibility notifier and all event calculations when we're in PTY mode (#10569) 2021-07-09 18:45:44 +00:00
_output.h Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
_stream.cpp Improve WriteCharsLegacy performance by increasing local buffer size (#10921) 2021-08-12 17:54:59 +00:00
_stream.h WriteCharsLegacy: Add some notes in comments and rename WC_ECHO (#9605) 2021-03-24 16:26:50 -05:00
alias.cpp Change backslashes in include statements to forward slashes (#8205) 2020-11-25 21:02:10 +00:00
alias.h add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
ApiRoutines.h Change backslashes in include statements to forward slashes (#8205) 2020-11-25 21:02:10 +00:00
cmdline.cpp WriteCharsLegacy: Add some notes in comments and rename WC_ECHO (#9605) 2021-03-24 16:26:50 -05:00
cmdline.h WriteCharsLegacy: Add some notes in comments and rename WC_ECHO (#9605) 2021-03-24 16:26:50 -05:00
CommandListPopup.cpp Change backslashes in include statements to forward slashes (#8205) 2020-11-25 21:02:10 +00:00
CommandListPopup.hpp add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
CommandNumberPopup.cpp WriteCharsLegacy: Add some notes in comments and rename WC_ECHO (#9605) 2021-03-24 16:26:50 -05:00
CommandNumberPopup.hpp Add explicit identifier to some constructors (#5652) 2020-04-29 16:50:47 -07:00
conapi.h Change backslashes in include statements to forward slashes (#8205) 2020-11-25 21:02:10 +00:00
conareainfo.cpp Replace basic_string_view<T> with span<const T> (#6921) 2020-07-15 16:40:42 +00:00
conareainfo.h Improve the legacy color conversions (#6358) 2020-06-08 19:05:06 +00:00
conddkrefs.h add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
conhost.rcv Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
conhostv2_traceviewpp.tvpp Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
conimeinfo.cpp Skip accessibility notifier and all event calculations when we're in PTY mode (#10569) 2021-07-09 18:45:44 +00:00
conimeinfo.h Replace basic_string_view<T> with span<const T> (#6921) 2020-07-15 16:40:42 +00:00
conserv.h add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
ConsoleArguments.cpp Fix startup race of resizing ConPTY (#10449) 2021-06-22 19:23:16 +00:00
ConsoleArguments.hpp Fix startup race of resizing ConPTY (#10449) 2021-06-22 19:23:16 +00:00
consoleInformation.cpp Standardize the color table order (#11602) 2021-11-04 22:13:22 +00:00
conv.h add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
convarea.cpp Make sure we don't hide the cursor until the IME starts (#7673) 2020-09-18 19:25:39 +00:00
conwinuserrefs.h add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
CopyFromCharPopup.cpp add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
CopyFromCharPopup.hpp Add explicit identifier to some constructors (#5652) 2020-04-29 16:50:47 -07:00
CopyToCharPopup.cpp add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
CopyToCharPopup.hpp add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
CursorBlinker.cpp Skip accessibility notifier and all event calculations when we're in PTY mode (#10569) 2021-07-09 18:45:44 +00:00
CursorBlinker.hpp Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
dbcs.cpp Replace gsl::at with a new til::at(span) for pre-checked bounds (#6925) 2020-07-15 10:29:36 -07:00
dbcs.h add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
directio.cpp Change backslashes in include statements to forward slashes (#8205) 2020-11-25 21:02:10 +00:00
directio.h Switch all DSR responses to appending instead of prepending (#7583) 2020-09-09 23:55:22 +00:00
dirs Merged PR 5677497: [Git2Git] Merged PR 5655213: Allow conhost to handoff to registered default app handler 2021-02-11 21:07:50 +00:00
getset.cpp Standardize the color table order (#11602) 2021-11-04 22:13:22 +00:00
getset.h Consolidate the interfaces for setting VT input modes (#11384) 2021-10-26 21:12:22 +00:00
globals.cpp Implement a pair of shims for cls, Clear-Host in conpty mode (#5627) 2020-04-30 21:53:31 +00:00
globals.h Introduce AtlasEngine - A new text rendering prototype (#11623) 2021-11-13 00:10:06 +00:00
handle.cpp Change backslashes in include statements to forward slashes (#8205) 2020-11-25 21:02:10 +00:00
handle.h Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
history.cpp Change backslashes in include statements to forward slashes (#8205) 2020-11-25 21:02:10 +00:00
history.h Replace macros with constexpr part 2 (#3416) 2019-11-04 07:37:47 -06:00
host-common.vcxitems Standardize the color table order (#11602) 2021-11-04 22:13:22 +00:00
IIoProvider.hpp Fix a bunch of spelling errors across the project (#4295) 2020-02-10 20:40:01 +00:00
init.cpp add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
init.hpp Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
input.cpp Change backslashes in include statements to forward slashes (#8205) 2020-11-25 21:02:10 +00:00
input.h Replace macros with constexpr part 2 (#3416) 2019-11-04 07:37:47 -06:00
inputBuffer.cpp [Conpty] Pass through request for mouse mode to the Terminal (#9970) 2021-05-07 02:46:11 +00:00
inputBuffer.hpp [Conpty] Pass through request for mouse mode to the Terminal (#9970) 2021-05-07 02:46:11 +00:00
inputKeyInfo.cpp Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
inputReadHandleData.cpp add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
inputReadHandleData.h add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
misc.cpp #10497: Do not force the font on output codepage change (#10591) 2021-07-08 21:10:35 +00:00
misc.h WriteCharsLegacy: Add some notes in comments and rename WC_ECHO (#9605) 2021-03-24 16:26:50 -05:00
ntprivapi.cpp Implement basic profile matching (#11390) 2021-10-08 00:40:10 +00:00
ntprivapi.hpp Implement basic profile matching (#11390) 2021-10-08 00:40:10 +00:00
output.cpp Add support for double-width/double-height lines in conhost (#8664) 2021-02-18 05:44:50 +00:00
output.h add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
outputStream.cpp Disable the acceptance of C1 control codes by default (#11690) 2021-11-17 23:40:31 +00:00
outputStream.hpp Disable the acceptance of C1 control codes by default (#11690) 2021-11-17 23:40:31 +00:00
popup.cpp Change backslashes in include statements to forward slashes (#8205) 2020-11-25 21:02:10 +00:00
popup.h Improve the legacy color conversions (#6358) 2020-06-08 19:05:06 +00:00
precomp.cpp Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
precomp.h Reduce Transient Allocations during Bulk Text Output (#8617) 2021-01-05 18:06:06 +00:00
PtySignalInputThread.cpp Implement and action for manually clearing the Terminal (and conpty) buffer (#10906) 2021-09-02 14:59:42 +00:00
PtySignalInputThread.hpp Implement and action for manually clearing the Terminal (and conpty) buffer (#10906) 2021-09-02 14:59:42 +00:00
readData.cpp Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
readData.hpp Merged PR 6034984: Fix a crash caused by improper buffer management w/ multiple clients 2021-05-11 16:56:43 +00:00
readDataCooked.cpp Merged PR 6285331: [Git2Git] Merged PR 6278637: Expose attached client process context to cooked read trace 2021-07-22 13:39:34 +00:00
readDataCooked.hpp Merged PR 6285331: [Git2Git] Merged PR 6278637: Expose attached client process context to cooked read trace 2021-07-22 13:39:34 +00:00
readDataDirect.cpp Merged PR 6034984: Fix a crash caused by improper buffer management w/ multiple clients 2021-05-11 16:56:43 +00:00
readDataDirect.hpp Merged PR 6034984: Fix a crash caused by improper buffer management w/ multiple clients 2021-05-11 16:56:43 +00:00
readDataRaw.cpp Merged PR 6034984: Fix a crash caused by improper buffer management w/ multiple clients 2021-05-11 16:56:43 +00:00
readDataRaw.hpp Merged PR 6034984: Fix a crash caused by improper buffer management w/ multiple clients 2021-05-11 16:56:43 +00:00
registry.cpp Standardize the color table order (#11602) 2021-11-04 22:13:22 +00:00
registry.hpp add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
renderData.cpp Standardize the color table order (#11602) 2021-11-04 22:13:22 +00:00
renderData.hpp Standardize the color table order (#11602) 2021-11-04 22:13:22 +00:00
renderFontDefaults.cpp Allow FontInfo{,Base,Desired} to store a font name > 32 wch (#3107) 2019-10-14 21:23:45 -07:00
renderFontDefaults.hpp Change backslashes in include statements to forward slashes (#8205) 2020-11-25 21:02:10 +00:00
res.rc Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
resource.h add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
runft.bat Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
runtests.bat Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
runut.bat Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
ScreenBufferRenderTarget.cpp Fix TerminalControl crash on exit (#10031) 2021-05-04 21:17:37 +00:00
ScreenBufferRenderTarget.hpp Fix TerminalControl crash on exit (#10031) 2021-05-04 21:17:37 +00:00
screenInfo.cpp Standardize the color table order (#11602) 2021-11-04 22:13:22 +00:00
screenInfo.hpp Implement and action for manually clearing the Terminal (and conpty) buffer (#10906) 2021-09-02 14:59:42 +00:00
scrolling.cpp Change backslashes in include statements to forward slashes (#8205) 2020-11-25 21:02:10 +00:00
scrolling.hpp Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
selection.cpp Improve conhost CPU usage during text selection (#11634) 2021-10-28 14:08:53 +02:00
selection.hpp Change backslashes in include statements to forward slashes (#8205) 2020-11-25 21:02:10 +00:00
selectionInput.cpp Standardize the color table order (#11602) 2021-11-04 22:13:22 +00:00
selectionState.cpp Change backslashes in include statements to forward slashes (#8205) 2020-11-25 21:02:10 +00:00
server.h Standardize the color table order (#11602) 2021-11-04 22:13:22 +00:00
settings.cpp Introduce AtlasEngine - A new text rendering prototype (#11623) 2021-11-13 00:10:06 +00:00
settings.hpp Introduce AtlasEngine - A new text rendering prototype (#11623) 2021-11-13 00:10:06 +00:00
sources.inc Migrate OSS up to f9b97c488 2021-11-09 13:39:28 -06:00
sources.test.inc Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
srvinit.cpp Add even MORE logging for defterm (#11537) 2021-10-19 13:29:18 -07:00
srvinit.h Persist inbox conhost; delegate control activities to it via a pipe (#10415) 2021-06-16 19:23:37 +00:00
stream.cpp Migrate OSS up to f9a844dbd 2021-09-21 16:22:57 -05:00
stream.h Change backslashes in include statements to forward slashes (#8205) 2020-11-25 21:02:10 +00:00
telemetry.cpp Migrate OSS up to f9a844dbd 2021-09-21 16:22:57 -05:00
telemetry.hpp Merged PR 6277720: [Git2Git] Merged PR 6275065: Trace console attach/detatch 2021-07-21 18:41:37 +00:00
tracing.cpp Migrate OSS up to f9a844dbd 2021-09-21 16:22:57 -05:00
tracing.hpp Merged PR 6285331: [Git2Git] Merged PR 6278637: Expose attached client process context to cooked read trace 2021-07-22 13:39:34 +00:00
utf8ToWideCharParser.cpp Fix a bunch of spelling errors across the project (#4295) 2020-02-10 20:40:01 +00:00
utf8ToWideCharParser.hpp add clang-format conf to the project, format the c++ code (#1141) 2019-06-11 13:27:09 -07:00
utils.cpp Change backslashes in include statements to forward slashes (#8205) 2020-11-25 21:02:10 +00:00
utils.hpp Change backslashes in include statements to forward slashes (#8205) 2020-11-25 21:02:10 +00:00
VtInputThread.cpp Add names to threads to make debugging a slight bit easier (#9801) 2021-04-14 10:56:52 +00:00
VtInputThread.hpp Change backslashes in include statements to forward slashes (#8205) 2020-11-25 21:02:10 +00:00
VtIo.cpp [Conpty] Pass through request for mouse mode to the Terminal (#9970) 2021-05-07 02:46:11 +00:00
VtIo.hpp Change backslashes in include statements to forward slashes (#8205) 2020-11-25 21:02:10 +00:00
writeData.cpp Merged PR 6034984: Fix a crash caused by improper buffer management w/ multiple clients 2021-05-11 16:56:43 +00:00
writeData.hpp Merged PR 6034984: Fix a crash caused by improper buffer management w/ multiple clients 2021-05-11 16:56:43 +00:00