git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Try URI quoting for embedded TAB and LF in pathnames

From
Linus Torvalds <torvalds@osdl.org>
Date
Oct 12, 2005, 19:52 UTC
Message-ID
<Pine.LNX.4.64.0510121220230.15297@g5.osdl.org>
In-Reply-To
<Pine.LNX.4.63.0510121452030.23242@iabervon.org>
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..
Previous: Daniel BarkalowNext: H. Peter Anvin
Message 19 of 33 in “[RFC] embedded TAB and LF in pathnames”
  1. Junio C HamanoOct 7, 2005
  2. Alex RiesenOct 7, 2005
  3. Junio C HamanoOct 7, 2005
  4. Alex RiesenOct 8, 2005
  5. Junio C HamanoOct 8, 2005
  6. Try URI quoting for embedded TAB and LF in pathnamesRobert Fitzsimons, Oct 8, 2005
  7. Junio C HamanoOct 8, 2005
  8. Junio C HamanoOct 8, 2005
  9. Paul EggertOct 11, 2005
  10. Junio C HamanoOct 11, 2005
  11. Linus TorvaldsOct 11, 2005
  12. Paul EggertOct 11, 2005
  13. Linus TorvaldsOct 11, 2005
  14. Paul EggertOct 11, 2005
  15. Linus TorvaldsOct 11, 2005
  16. Paul EggertOct 12, 2005
  17. Linus TorvaldsOct 12, 2005
  18. Daniel BarkalowOct 12, 2005
  19. Linus TorvaldsOct 12, 2005
  20. H. Peter AnvinOct 12, 2005
  21. Junio C HamanoOct 9, 2005
  22. Junio C HamanoOct 12, 2005
  23. Linus TorvaldsOct 12, 2005
  24. H. Peter AnvinOct 12, 2005
  25. Johannes SchindelinOct 12, 2005
  26. Junio C HamanoOct 12, 2005
  27. Paul EggertOct 14, 2005
  28. Linus TorvaldsOct 14, 2005
  29. Linus TorvaldsOct 12, 2005
  30. Paul EggertOct 14, 2005
  31. Linus TorvaldsOct 14, 2005
  32. H. Peter AnvinOct 14, 2005
  33. Junio C HamanoOct 14, 2005

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.