Skip to content

Commit 945bf20

Browse files
committed
Fix a bug related to string ends in the protocol
1 parent 3542882 commit 945bf20

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

main/src/emulator/TextTerm.ts

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,12 @@ enum ParserState {
106106
CSI_START,
107107
CSI_PARAMS,
108108
OSC_CODE,
109+
OSC_CODE_STRING_ESC_TERMINATOR,
109110
OSC_ITERM_PARMS,
110111
OSC_ITERM_PAYLOAD,
111112
OSC_ITERM_PAYLOAD_ESC,
112113
OSC_PARAMS,
114+
OSC_PARAMS_STRING_ESC_TERMINATOR,
113115
CHARSET,
114116
DCS_START,
115117
DCS_STRING,
@@ -1242,6 +1244,8 @@ export class TextEmulator implements TextEmulatorApi {
12421244
case ParserState.OSC_ITERM_PAYLOAD:
12431245
case ParserState.OSC_ITERM_PAYLOAD_ESC:
12441246
case ParserState.OSC_PARAMS:
1247+
case ParserState.OSC_CODE_STRING_ESC_TERMINATOR:
1248+
case ParserState.OSC_PARAMS_STRING_ESC_TERMINATOR:
12451249
i = this.#processDataOSC(codePoint, i);
12461250
break;
12471251

@@ -2011,11 +2015,7 @@ export class TextEmulator implements TextEmulatorApi {
20112015
// OSC Ps ; Pt ST
20122016
// OSC Ps ; Pt BEL
20132017
// Set Text Parameters.
2014-
const isTerminator = codePoint === CODEPOINT_BEL || codePoint === CODEPOINT_ESC;
2015-
if (codePoint === CODEPOINT_ESC) { // ESC \ means ST (string terminator)
2016-
i++; // Assume the next codepoint is \ and skip it.
2017-
}
2018-
2018+
const isTerminator = codePoint === CODEPOINT_BEL;
20192019
switch (this.#state) {
20202020
case ParserState.OSC_CODE:
20212021
if (codePoint >= CODEPOINT_ZERO && codePoint <= CODEPOINT_NINE) {
@@ -2027,6 +2027,8 @@ export class TextEmulator implements TextEmulatorApi {
20272027
} else {
20282028
this.#state = ParserState.OSC_PARAMS;
20292029
}
2030+
} else if (codePoint === CODEPOINT_ESC) {
2031+
this.#state = ParserState.OSC_CODE_STRING_ESC_TERMINATOR;
20302032
} else {
20312033
if (isTerminator) {
20322034
this.#params.endParameter();
@@ -2037,17 +2039,37 @@ export class TextEmulator implements TextEmulatorApi {
20372039
}
20382040
break;
20392041

2042+
case ParserState.OSC_CODE_STRING_ESC_TERMINATOR:
2043+
if (codePoint === CODEPOINT_BACKSLASH) { // ESC \ means ST (string terminator)
2044+
this.#params.endParameter();
2045+
this.#executeOSC();
2046+
}
2047+
this.#params.reset();
2048+
this.#state = ParserState.NORMAL;
2049+
return i;
2050+
20402051
case ParserState.OSC_PARAMS:
20412052
if (codePoint === CODEPOINT_SEMICOLON) {
20422053
this.#params.endParameter();
2043-
} else if (! isTerminator) {
2044-
this.#params.appendParameterCodePoint(codePoint);
2045-
} else {
2054+
} else if (codePoint === CODEPOINT_ESC) {
2055+
this.#state = ParserState.OSC_PARAMS_STRING_ESC_TERMINATOR;
2056+
} else if (isTerminator) {
20462057
this.#params.endParameter();
20472058
this.#executeOSC();
20482059
this.#params.reset();
20492060
this.#state = ParserState.NORMAL;
2061+
} else {
2062+
this.#params.appendParameterCodePoint(codePoint);
2063+
}
2064+
break;
2065+
2066+
case ParserState.OSC_PARAMS_STRING_ESC_TERMINATOR:
2067+
if (codePoint === CODEPOINT_BACKSLASH) { // ESC \ means ST (string terminator)
2068+
this.#params.endParameter();
2069+
this.#executeOSC();
20502070
}
2071+
this.#params.reset();
2072+
this.#state = ParserState.NORMAL;
20512073
break;
20522074

20532075
case ParserState.OSC_ITERM_PARMS:

0 commit comments

Comments
 (0)