packages/apps/AndroidTerm
リビジョン | 14c7cebbafa3c8806252db3830dad478e33f5113 (tree) |
---|---|
日時 | 2012-03-26 10:21:37 |
作者 | Steven Luo <steven+android@stev...> |
コミッター | Jack Palevich |
Properly handle UTF-8 sequences decoding to C1 control characters
Applications which emit UTF-8 sequences that decode to C1 control
characters expect these sequences to be interpreted as C1 control
characters, so send them back through process() instead of trying to
emit them.
Signed-off-by: Jack Palevich <jackpal@google.com>
@@ -515,8 +515,12 @@ public class TerminalEmulator { | ||
515 | 515 | } |
516 | 516 | |
517 | 517 | private void process(byte b) { |
518 | + process(b, true); | |
519 | + } | |
520 | + | |
521 | + private void process(byte b, boolean doUTF8) { | |
518 | 522 | // Let the UTF-8 decoder try to handle it if we're in UTF-8 mode |
519 | - if (mUTF8Mode && handleUTF8Sequence(b)) { | |
523 | + if (doUTF8 && mUTF8Mode && handleUTF8Sequence(b)) { | |
520 | 524 | return; |
521 | 525 | } |
522 | 526 |
@@ -654,7 +658,15 @@ public class TerminalEmulator { | ||
654 | 658 | decoder.reset(); |
655 | 659 | decoder.decode(byteBuf, charBuf, true); |
656 | 660 | decoder.flush(charBuf); |
657 | - emit(charBuf.array()); | |
661 | + | |
662 | + char[] chars = charBuf.array(); | |
663 | + if (chars[0] >= 0x80 && chars[0] <= 0x9f) { | |
664 | + /* Sequence decoded to a C1 control character which needs | |
665 | + to be sent through process() again */ | |
666 | + process((byte) chars[0], false); | |
667 | + } else { | |
668 | + emit(chars); | |
669 | + } | |
658 | 670 | |
659 | 671 | byteBuf.clear(); |
660 | 672 | charBuf.clear(); |