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

Re: [JGIT PATCH 4/6] Add QuotedString class to handle C-style quoting rules

From
Robin Rosenberg <robin.rosenberg@dewire.com>
Date
Dec 11, 2008, 00:33 UTC
Message-ID
<200812110133.51614.robin.rosenberg@dewire.com>
In-Reply-To
<20081210234130.GB32487@spearce.org>
torsdag 11 december 2008 00:41:30 skrev Shawn O. Pearce:
Show 23 quoted lines
> > > +	public void testQuote_OctalAll() {
> > > +		assertQuote("\1", "\\001");
> > > +		assertQuote("~", "\\176");
> > > +		assertQuote("\u00ff", "\\303\\277"); // \u00ff in UTF-8
> > > +	}
> >
> > What do we do with non-UTF8 names? I think we should
> > follow the logic we use when parsing commits and paths
> > in other places.
> 
> Then we're totally f'd.
> 
> Git has no specific encoding on file names.  If we get a standard
> Java Unicode string and get asked to quote it characters with
> code points above 127 need to be escaped as an octal escape code
> according to the Git style.  Further the Git style only permits
> octal escapes that result in a value <= 255, aka an unsigned char.
> 
> The name needs to be encoded into an 8-bit encoding, and UTF-8 is
> the only encoding that will represent every valid Unicode character.
> Elsewhere we sort of take the attitude that when writing data *out*
> we produce UTF-8, even if we read in ISO-whatever.  Here I'm doing
> the same thing.
So this should pass, right?
	public void testDeQuote_Latin1() {
		assertDequote("\u00c5ngstr\u00f6m", "\\305ngstr\\366m"); // Latin1
	}
	public void testDeQuote_UTF8() {
		assertDequote("\u00c5ngstr\u00f6m", "\\303\\205ngstr\\303\\266m");
	}

And possibly these actuall unquoted names, which can be produced when core.quotepath is false

	public void testDeQuote_Rawlatin() {
		assertDequote("\u00c5ngstr\u00f6m", "\305ngstr\366m");
	}
	public void testDeQuote_RawUTF8() {
		assertDequote("\u00c5ngstr\u00f6m", "\303\205ngstr\303\266m");
	}

You also reversed the arguments to testQuote. It think we should follow the "expected"-first conventions here too. The case above works neither way. Using Constant.encode in the test is kind of dangerous as it does too many conversions, so you don't know what you're testing anymore. Changing assertDequote like this makes us able to feed byte sequences as strings to the test method (which we cannot do if we assume UTF-8 encoding). ISO- latin-encoding allows any byte sequence to be entered conveniently.

	private static void assertDequote(final String exp, final String in) {
		final byte[] b;
		try {
			b = ('"' + in + '"').getBytes("ISO-8859-1");
		} catch (UnsupportedEncodingException e) {
			throw new RuntimeException(e);
		}
		final String r = C.dequote(b, 0, b.length);
		assertEquals(exp, r);
	}
-- robin
Previous: Shawn O. PearceNext: Shawn O. Pearce
Message 10 of 11 in “RawParseUtil improvements”
  1. 0/6 RawParseUtil improvementsShawn O. Pearce, Dec 10, 2008
  2. 1/6 Simplify RawParseUtils.nextLF invocationsShawn O. Pearce, Dec 10, 2008
  3. 2/6 Simplify RawParseUtils next and nextLF loopsShawn O. Pearce, Dec 10, 2008
  4. 3/6 Correct Javadoc of RawParseUtils next and nextLF methodsShawn O. Pearce, Dec 10, 2008
  5. 4/6 Add QuotedString class to handle C-style quoting rulesShawn O. Pearce, Dec 10, 2008
  6. 5/6 Add Bourne style quoting for TransportGitSshShawn O. Pearce, Dec 10, 2008
  7. 6/6 Add ~user friendly Bourne style quoting for TransportGitSshShawn O. Pearce, Dec 10, 2008
  8. Robin RosenbergDec 10, 2008
  9. Shawn O. PearceDec 10, 2008
  10. Robin RosenbergDec 11, 2008
  11. 4/6 Add QuotedString class to handle Git path style quoting rulesShawn O. Pearce, Dec 11, 2008

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.