]> source.dussan.org Git - jgit.git/commitdiff
Fix QuotedString.GIT_PATH escaping rules 28/1528/1
authorShawn O. Pearce <spearce@spearce.org>
Fri, 3 Sep 2010 20:01:57 +0000 (13:01 -0700)
committerShawn O. Pearce <spearce@spearce.org>
Fri, 3 Sep 2010 20:02:01 +0000 (13:02 -0700)
We shouldn't escape non-special ASCII characters such as '@' or '~'.
These are valid in a path name on POSIX systems, and may appear as
part of a path in a GNU or Git style patch script.  Escaping them
into octal just obfuscates the user's intent, with no gain.

When parsing an escaped octal sequence, we must parse no more
than 3 digits.  That is, "\1002" is actually "@2", not the Unicode
character \u0202.

Change-Id: I3a849a0d318e69b654f03fd559f5d7f99dd63e5c
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
org.eclipse.jgit.test/tst/org/eclipse/jgit/util/QuotedStringGitPathStyleTest.java
org.eclipse.jgit/src/org/eclipse/jgit/util/QuotedString.java

index 4a161fa01c6bd7086662a400e4d3b2c009f4a436..1af45c2272667c0d9ca49bedc9d33c67931fc22a 100644 (file)
@@ -153,7 +153,7 @@ public class QuotedStringGitPathStyleTest extends TestCase {
 
        public void testQuote_OctalAll() {
                assertQuote("\\001", "\1");
-               assertQuote("\\176", "~");
+               assertQuote("\\177", "\u007f");
                assertQuote("\\303\\277", "\u00ff"); // \u00ff in UTF-8
        }
 
@@ -184,4 +184,9 @@ public class QuotedStringGitPathStyleTest extends TestCase {
        public void testQuote_Ang() {
                assertQuote("\\303\\205ngstr\\303\\266m", "\u00c5ngstr\u00f6m");
        }
+
+       public void testQuoteAtAndNumber() {
+               assertSame("abc@2x.png", GIT_PATH.quote("abc@2x.png"));
+               assertDequote("abc@2x.png", "abc\\1002x.png");
+       }
 }
index 7e5bde7582fc3dbb9a1936d3daa828effcc73de8..f920af6116e49465d6b8d6f4c96c94ffe7a6887f 100644 (file)
@@ -222,14 +222,24 @@ public abstract class QuotedString {
                        for (int i = 'A'; i <= 'Z'; i++)
                                quote[i] = 0;
                        quote[' '] = 0;
+                       quote['$'] = 0;
+                       quote['%'] = 0;
+                       quote['&'] = 0;
+                       quote['*'] = 0;
                        quote['+'] = 0;
                        quote[','] = 0;
                        quote['-'] = 0;
                        quote['.'] = 0;
                        quote['/'] = 0;
+                       quote[':'] = 0;
+                       quote[';'] = 0;
                        quote['='] = 0;
+                       quote['?'] = 0;
+                       quote['@'] = 0;
                        quote['_'] = 0;
                        quote['^'] = 0;
+                       quote['|'] = 0;
+                       quote['~'] = 0;
 
                        quote['\u0007'] = 'a';
                        quote['\b'] = 'b';
@@ -335,7 +345,7 @@ public abstract class QuotedString {
                                case '2':
                                case '3': {
                                        int cp = in[inPtr - 1] - '0';
-                                       while (inPtr < inEnd) {
+                                       for (int n = 1; n < 3 && inPtr < inEnd; n++) {
                                                final byte c = in[inPtr];
                                                if ('0' <= c && c <= '7') {
                                                        cp <<= 3;