Skip to content

Commit

Permalink
Filter out escape sequence 'character set' select
Browse files Browse the repository at this point in the history
reported #92 fix after #95 PrintStream copy of OutputStream
  • Loading branch information
hboutemy committed Dec 2, 2017
1 parent 5f8eb45 commit 4b24c09
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ protected void processUnknownOperatingSystemCommand(int command, String param) {
* @param options
* @return true if the charcter set select command was processed.
*/
private boolean processCharsetSelect(ArrayList<Object> options) throws IOException {
private boolean processCharsetSelect(ArrayList<Object> options) {
int set = optionInt(options, 0);
char seq = ((Character) options.get(1)).charValue();
processCharsetSelect(set, seq);
Expand Down
29 changes: 29 additions & 0 deletions jansi/src/main/java/org/fusesource/jansi/AnsiPrintStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public AnsiPrintStream(PrintStream ps) { // expected diff with AnsiOutputStream.
private static final int LOOKING_FOR_OSC_COMMAND_END = 6;
private static final int LOOKING_FOR_OSC_PARAM = 7;
private static final int LOOKING_FOR_ST = 8;
private static final int LOOKING_FOR_CHARSET = 9;

int state = LOOKING_FOR_FIRST_ESC_CHAR;

Expand All @@ -69,6 +70,8 @@ public AnsiPrintStream(PrintStream ps) { // expected diff with AnsiOutputStream.
private static final int SECOND_OSC_CHAR = ']';
private static final int BEL = 7;
private static final int SECOND_ST_CHAR = '\\';
private static final int SECOND_CHARSET0_CHAR = '(';
private static final int SECOND_CHARSET1_CHAR = ')';

@Override
protected boolean filter(int data) { // expected diff with AnsiOutputStream.java
Expand All @@ -87,6 +90,12 @@ protected boolean filter(int data) { // expected diff with AnsiOutputStream.java
state = LOOKING_FOR_NEXT_ARG;
} else if (data == SECOND_OSC_CHAR) {
state = LOOKING_FOR_OSC_COMMAND;
} else if (data == SECOND_CHARSET0_CHAR) {
options.add(new Integer('0'));

This comment has been minimized.

Copy link
@michael-o

michael-o Dec 16, 2017

Contributor

Don't use the constructor, use valueOf.

This comment has been minimized.

Copy link
@hboutemy

hboutemy Dec 17, 2017

Author Collaborator

good idea: done (on the 3 locations for AnsiOutputStream and AnsiPrintStream)
thank you

state = LOOKING_FOR_CHARSET;
} else if (data == SECOND_CHARSET1_CHAR) {
options.add(new Integer('1'));

This comment has been minimized.

Copy link
@michael-o

michael-o Dec 16, 2017

Contributor

Don't use the constructor, use valueOf.

state = LOOKING_FOR_CHARSET;
} else {
reset(false);
}
Expand Down Expand Up @@ -189,6 +198,11 @@ protected boolean filter(int data) { // expected diff with AnsiOutputStream.java
state = LOOKING_FOR_OSC_PARAM;
}
break;

case LOOKING_FOR_CHARSET:
options.add(new Character((char) data));

This comment has been minimized.

Copy link
@michael-o

michael-o Dec 16, 2017

Contributor

Don't use the constructor, use valueOf.

reset(processCharsetSelect(options));
break;
}

// Is it just too long?
Expand Down Expand Up @@ -726,6 +740,21 @@ protected void processChangeWindowTitle(String label) {
protected void processUnknownOperatingSystemCommand(int command, String param) {
}

/**
* Process character set sequence.
* @param options
* @return true if the charcter set select command was processed.
*/
private boolean processCharsetSelect(ArrayList<Object> options) {
int set = optionInt(options, 0);
char seq = ((Character) options.get(1)).charValue();
processCharsetSelect(set, seq);
return true;
}

protected void processCharsetSelect(int set, char seq) {
}

private int optionInt(ArrayList<Object> options, int index) {
if (options.size() <= index)
throw new IllegalArgumentException();
Expand Down

0 comments on commit 4b24c09

Please sign in to comment.