Page MenuHomePhabricator

Incorrect parsing of leading or trailing semicolon inside SGR
Closed, ResolvedPublic

Description

In Terminology, both of these escape sequences

\e[31;m
\e[;31m

turn the foreground color to red, and preserve the attributes that have previously been turned on.

I've tested many other terminal emulators, and in all of them the extra semicolon stands for delimiting a default 0 parameter turning off every attribute. That is, the first sequence turns off all the attributes, the second one turns them all off and then switches to red foreground.

Similarly,

\e[46;;31m

results in cyan background in Terminology, while default background in other emulators.

ECMA-48 5.4.2 g) explicitly states that the behavior of all the other emulators is the correct one:

If the parameter string starts with the bit combination 03/11, an empty parameter sub-string is assumed preceding the separator; if the arameter string terminates with the bit combination 03/11, an empty parameter sub-string is assumed following the separator; if the parameter string contains successive bit combinations 03/11, empty parameter sub-strings are assumed between the separators.

I'm not sure whether other sequences are also affected; for example, '\e[;5H' is handled correctly in Terminology, 5 is taken as the second parameter where the first one gets its implicit default of 1.