Skip to content

Commit 693404f

Browse files
MatanZNadeem Anwar
authored andcommitted
Ignore line feeds (and similar control characters) inside base64 data
1 parent a46a60b commit 693404f

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

terminal-emulator/src/main/java/com/termux/terminal/TerminalEmulator.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -628,14 +628,14 @@ public void processCodePoint(int b) {
628628
case 10: // Line feed (LF, \n).
629629
case 11: // Vertical tab (VT, \v).
630630
case 12: // Form feed (FF, \f).
631-
if(mEscapeState != ESC_P || !ESC_P_sixel) {
632-
// Ignore CR/LF inside sixels
631+
if((mEscapeState != ESC_P || !ESC_P_sixel) && ESC_OSC_colon <= 0) {
632+
// Ignore CR/LF inside sixels or iterm2 data
633633
doLinefeed();
634634
}
635635
break;
636636
case 13: // Carriage return (CR, \r).
637-
if(mEscapeState != ESC_P || !ESC_P_sixel) {
638-
// Ignore CR/LF inside sixels
637+
if((mEscapeState != ESC_P || !ESC_P_sixel) && ESC_OSC_colon <= 0) {
638+
// Ignore CR/LF inside sixels or iterm2 data
639639
setCursorCol(mLeftMargin);
640640
}
641641
break;
@@ -2166,6 +2166,8 @@ private void doOscEsc(int b) {
21662166
/** An Operating System Controls (OSC) Set Text Parameters. May come here from BEL or ST. */
21672167
private void doOscSetTextParameters(String bellOrStringTerminator) {
21682168
int value = -1;
2169+
int osc_colon = ESC_OSC_colon;
2170+
ESC_OSC_colon = -1;
21692171
String textParameter = "";
21702172
// Extract initial $value from initial "$value;..." string.
21712173
for (int mOSCArgTokenizerIndex = 0; mOSCArgTokenizerIndex < mOSCOrDeviceControlArgs.length(); mOSCArgTokenizerIndex++) {
@@ -2363,21 +2365,21 @@ private void doOscSetTextParameters(String bellOrStringTerminator) {
23632365
finishSequence();
23642366
return;
23652367
}
2366-
if (ESC_OSC_colon >= 0 && mOSCOrDeviceControlArgs.length() > ESC_OSC_colon) {
2367-
while (mOSCOrDeviceControlArgs.length() - ESC_OSC_colon < 4) {
2368+
if (osc_colon >= 0 && mOSCOrDeviceControlArgs.length() > osc_colon) {
2369+
while (mOSCOrDeviceControlArgs.length() - osc_colon < 4) {
23682370
mOSCOrDeviceControlArgs.append('=');
23692371
}
23702372
try {
2371-
byte[] decoded = Base64.decode(mOSCOrDeviceControlArgs.substring(ESC_OSC_colon), 0);
2373+
byte[] decoded = Base64.decode(mOSCOrDeviceControlArgs.substring(osc_colon), 0);
23722374
for (int i = 0 ; i < decoded.length; i++) {
23732375
ESC_OSC_data.add(decoded[i]);
23742376
}
23752377
} catch(Exception e) {
23762378
// Ignore non-Base64 data.
23772379
}
2378-
mOSCOrDeviceControlArgs.setLength(ESC_OSC_colon);
2380+
mOSCOrDeviceControlArgs.setLength(osc_colon);
23792381
}
2380-
if (ESC_OSC_colon >= 0) {
2382+
if (osc_colon >= 0) {
23812383
byte[] result = new byte[ESC_OSC_data.size()];
23822384
for(int i = 0; i < ESC_OSC_data.size(); i++) {
23832385
result[i] = ESC_OSC_data.get(i).byteValue();

0 commit comments

Comments
 (0)