From: Linus Torvalds Date: Wed, 12 Oct 2005 19:52:41 GMT Subject: Re: [PATCH] Try URI quoting for embedded TAB and LF in pathnames Message-ID: In-Reply-To: On Wed, 12 Oct 2005, Daniel Barkalow wrote: > > I think it's actually sufficient to escape 0x00-0x1f and 0x7f; those > ranges are both easy They are indeed easy. > and, as far as I can tell, include all of the control > characters that do annoying things. Nope. The traditional vt100 escape sequence is "ESC" followed by a character to indicate the type of sequence (the most common one is '['). That's all 7-bit and fine. HOWEVER, they made the 8-bit extension be such that any of these vt100 begin sequences where the second character is in the appropriate range can be instead shortened by one character, by instead using a single 8-bit character of "0x80+(char-0x40)". Ie the traditional "ESC + '['" (\x1b\x5b) can also be written as a single '\x9b' character, aka CSI. In other words, 0x80-0x9f are _all_ just vt100 shorthand for ESC+'@' through ESC+'_'. (I guess it's not strictly "vt100" any more - it's the extended vt220 format). > I think escape, backspace, delete, and > bell are the only ones we'd rather the terminal not get; beyond that, > patches with screwy filenames look screwy, but don't screw up anything > outside of the filename. Try this on a (non-UTF-8) xterm: echo -en '\x9b5B---\x9b1A---\x9b4A\r' and it should do: - move cursor 5 lines down - print "---" - move cursor 1 line up - print "---" - move cursor 4 lines up - return carriage to beginning. In other words, your screen should end up looking something like this: [torvalds@g5 ~]$ echo -en '\x9b5B---\x9b1A---\x9b4A\r' [torvalds@g5 ~]$ --- --- where that "staircase" of two "---" things was done with cursor movements. And that's a _benign_ sequence. You can do all kinds of funky stuff that really screws up the user experience. Including have the thing echo keys to you that you didn't type: echo -en '\x9b5n' or lock the keyboard (I don't think any of the terminal emulators implement the latter, or some of the other stranger sequences - things to do double-wide characters etc). Linus PS. You can do all the same in UTF-8 one, but then you'll have to add a \xc2 before the \x9b: echo -en '\xc2\x9b5B---\xc2\x9b1A---\xc2\x9b4A\r' etc..