{"thread":{"id":"16674","subject":"[JGIT PATCH 6/6] Add ~user friendly Bourne style quoting for TransportGitSsh","startedAt":"2008-12-10T22:05:45Z","lastAt":"2008-12-11T00:57:42Z","messageCount":11,"participants":["Shawn O. Pearce","Robin Rosenberg"],"isPatch":true,"patchVersion":1,"patchTotal":6},"messages":[{"id":"97525","messageId":"1228946751-12708-1-git-send-email-spearce@spearce.org","threadId":"16674","inReplyTo":null,"subject":"[JGIT PATCH 0/6] RawParseUtil improvements","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2008-12-10T22:05:45Z","receivedAt":"2008-12-10T22:05:45Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"I'm working on patch parsing support for JGit, so I can rely on\nit in Gerrit 2.  Currently Gerrit 1 uses a bastard chunk of code\nI ripped out in an hour to scan the output of \"git diff\"; its not\nsuitable for long-term appliction.\n\nThis series improves RawParseUtils code clarity, and then adds\nsupport for the C-style quoting rules used by git diff when file\nnames contain \"special\" characters like LF.\n\nI'm working on patch parsing right now; but I wanted to send this\npreliminary series out so you aren't drowning in code to review.\n\n\nShawn O. Pearce (6):\n  Simplify RawParseUtils.nextLF invocations\n  Simplify RawParseUtils next and nextLF loops\n  Correct Javadoc of RawParseUtils next and nextLF methods\n  Add QuotedString class to handle C-style quoting rules\n  Add Bourne style quoting for TransportGitSsh\n  Add ~user friendly Bourne style quoting for TransportGitSsh\n\n .../jgit/util/QuotedStringBourneStyleTest.java     |  111 ++++++\n .../util/QuotedStringBourneUserPathStyleTest.java  |  130 +++++++\n .../spearce/jgit/util/QuotedStringC_StyleTest.java |  144 ++++++++\n .../src/org/spearce/jgit/lib/ObjectChecker.java    |    4 +-\n .../src/org/spearce/jgit/revwalk/RevTag.java       |    2 +-\n .../spearce/jgit/transport/TransportGitSsh.java    |   38 +--\n .../src/org/spearce/jgit/util/QuotedString.java    |  364 ++++++++++++++++++++\n .../src/org/spearce/jgit/util/RawParseUtils.java   |   45 ++-\n 8 files changed, 783 insertions(+), 55 deletions(-)\n create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/util/QuotedStringBourneStyleTest.java\n create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/util/QuotedStringBourneUserPathStyleTest.java\n create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/util/QuotedStringC_StyleTest.java\n create mode 100644 org.spearce.jgit/src/org/spearce/jgit/util/QuotedString.java\n"},{"id":"97528","messageId":"1228946751-12708-2-git-send-email-spearce@spearce.org","threadId":"16674","inReplyTo":"1228946751-12708-1-git-send-email-spearce@spearce.org","subject":"[JGIT PATCH 1/6] Simplify RawParseUtils.nextLF invocations","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2008-12-10T22:05:46Z","receivedAt":"2008-12-10T22:05:46Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Most of the time when we call next('\\n') or nextLF('\\n') we really\nmeant to just say nextLF(), which is logically identical to next()\nbut could be micro-optimized for the LF byte.\n\nThis refactoring shifts the calls to use the new nextLF wrapper for\nnext('\\n'), so we can later chose to make this optimization, or to\nleave the code as-is.  But either way the call sites are now much\nclearer to read.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n .../src/org/spearce/jgit/lib/ObjectChecker.java    |    4 +-\n .../src/org/spearce/jgit/revwalk/RevTag.java       |    2 +-\n .../src/org/spearce/jgit/util/RawParseUtils.java   |   25 ++++++++++++++++----\n 3 files changed, 23 insertions(+), 8 deletions(-)\n\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectChecker.java b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectChecker.java\nindex b303d6f..75e3c77 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectChecker.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/ObjectChecker.java\n@@ -205,11 +205,11 @@ public void checkTag(final byte[] raw) throws CorruptObjectException {\n \n \t\tif ((ptr = match(raw, ptr, type)) < 0)\n \t\t\tthrow new CorruptObjectException(\"no type header\");\n-\t\tptr = nextLF(raw, ptr, '\\n');\n+\t\tptr = nextLF(raw, ptr);\n \n \t\tif ((ptr = match(raw, ptr, tag)) < 0)\n \t\t\tthrow new CorruptObjectException(\"no tag header\");\n-\t\tptr = nextLF(raw, ptr, '\\n');\n+\t\tptr = nextLF(raw, ptr);\n \n \t\tif ((ptr = match(raw, ptr, tagger)) < 0)\n \t\t\tthrow new CorruptObjectException(\"no tagger header\");\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/revwalk/RevTag.java b/org.spearce.jgit/src/org/spearce/jgit/revwalk/RevTag.java\nindex bbb18ee..77a55cd 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/revwalk/RevTag.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/revwalk/RevTag.java\n@@ -90,7 +90,7 @@ void parseCanonical(final RevWalk walk, final byte[] rawTag)\n \t\tobject = walk.lookupAny(walk.idBuffer, oType);\n \n \t\tint p = pos.value += 4; // \"tag \"\n-\t\tfinal int nameEnd = RawParseUtils.next(rawTag, p, '\\n') - 1;\n+\t\tfinal int nameEnd = RawParseUtils.nextLF(rawTag, p) - 1;\n \t\tname = RawParseUtils.decode(Constants.CHARSET, rawTag, p, nameEnd);\n \t\tbuffer = rawTag;\n \t\tflags |= PARSED;\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/util/RawParseUtils.java b/org.spearce.jgit/src/org/spearce/jgit/util/RawParseUtils.java\nindex 4b96439..10c2239 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/util/RawParseUtils.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/util/RawParseUtils.java\n@@ -230,6 +230,21 @@ public static final int next(final byte[] b, int ptr, final char chrA) {\n \t}\n \n \t/**\n+\t * Locate the first position after the next LF.\n+\t * <p>\n+\t * This method stops on the first '\\n' it finds.\n+\t * \n+\t * @param b\n+\t *            buffer to scan.\n+\t * @param ptr\n+\t *            position within buffer to start looking for LF at.\n+\t * @return new position just after the first LF found.\n+\t */\n+\tpublic static final int nextLF(final byte[] b, int ptr) {\n+\t\treturn next(b, ptr, '\\n');\n+\t}\n+\n+\t/**\n \t * Locate the first position after either the given character or LF.\n \t * <p>\n \t * This method stops on the first match it finds from either chrA or '\\n'.\n@@ -296,7 +311,7 @@ public static final int committer(final byte[] b, int ptr) {\n \t\twhile (ptr < sz && b[ptr] == 'p')\n \t\t\tptr += 48; // skip this parent.\n \t\tif (ptr < sz && b[ptr] == 'a')\n-\t\t\tptr = next(b, ptr, '\\n');\n+\t\t\tptr = nextLF(b, ptr);\n \t\treturn match(b, ptr, committer);\n \t}\n \n@@ -320,7 +335,7 @@ public static final int encoding(final byte[] b, int ptr) {\n \t\t\t\treturn -1;\n \t\t\tif (b[ptr] == 'e')\n \t\t\t\tbreak;\n-\t\t\tptr = next(b, ptr, '\\n');\n+\t\t\tptr = nextLF(b, ptr);\n \t\t}\n \t\treturn match(b, ptr, encoding);\n \t}\n@@ -342,7 +357,7 @@ public static Charset parseEncoding(final byte[] b) {\n \t\tfinal int enc = encoding(b, 0);\n \t\tif (enc < 0)\n \t\t\treturn Constants.CHARSET;\n-\t\tfinal int lf = next(b, enc, '\\n');\n+\t\tfinal int lf = nextLF(b, enc);\n \t\treturn Charset.forName(decode(Constants.CHARSET, b, enc, lf - 1));\n \t}\n \n@@ -505,7 +520,7 @@ public static final int commitMessage(final byte[] b, int ptr) {\n \t\t// header line type is.\n \t\t//\n \t\twhile (ptr < sz && b[ptr] != '\\n')\n-\t\t\tptr = next(b, ptr, '\\n');\n+\t\t\tptr = nextLF(b, ptr);\n \t\tif (ptr < sz && b[ptr] == '\\n')\n \t\t\treturn ptr + 1;\n \t\treturn -1;\n@@ -529,7 +544,7 @@ public static final int endOfParagraph(final byte[] b, final int start) {\n \t\tint ptr = start;\n \t\tfinal int sz = b.length;\n \t\twhile (ptr < sz && b[ptr] != '\\n')\n-\t\t\tptr = next(b, ptr, '\\n');\n+\t\t\tptr = nextLF(b, ptr);\n \t\twhile (0 < ptr && start < ptr && b[ptr - 1] == '\\n')\n \t\t\tptr--;\n \t\treturn ptr;\n-- \n1.6.1.rc2.299.gead4c\n"},{"id":"97529","messageId":"1228946751-12708-3-git-send-email-spearce@spearce.org","threadId":"16674","inReplyTo":"1228946751-12708-2-git-send-email-spearce@spearce.org","subject":"[JGIT PATCH 2/6] Simplify RawParseUtils next and nextLF loops","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2008-12-10T22:05:47Z","receivedAt":"2008-12-10T22:05:47Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"We always need ptr + 1 after we read the current position,\nso we might as well do the much more common foo[ptr++]. A\ngood JIT would be more likely to optimize this case over\nthe weird else branch we had.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n .../src/org/spearce/jgit/util/RawParseUtils.java   |   12 ++++--------\n 1 files changed, 4 insertions(+), 8 deletions(-)\n\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/util/RawParseUtils.java b/org.spearce.jgit/src/org/spearce/jgit/util/RawParseUtils.java\nindex 10c2239..5a40911 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/util/RawParseUtils.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/util/RawParseUtils.java\n@@ -221,10 +221,8 @@ public static final int parseTimeZoneOffset(final byte[] b, int ptr) {\n \tpublic static final int next(final byte[] b, int ptr, final char chrA) {\n \t\tfinal int sz = b.length;\n \t\twhile (ptr < sz) {\n-\t\t\tif (b[ptr] == chrA)\n-\t\t\t\treturn ptr + 1;\n-\t\t\telse\n-\t\t\t\tptr++;\n+\t\t\tif (b[ptr++] == chrA)\n+\t\t\t\treturn ptr;\n \t\t}\n \t\treturn ptr;\n \t}\n@@ -260,11 +258,9 @@ public static final int nextLF(final byte[] b, int ptr) {\n \tpublic static final int nextLF(final byte[] b, int ptr, final char chrA) {\n \t\tfinal int sz = b.length;\n \t\twhile (ptr < sz) {\n-\t\t\tfinal byte c = b[ptr];\n+\t\t\tfinal byte c = b[ptr++];\n \t\t\tif (c == chrA || c == '\\n')\n-\t\t\t\treturn ptr + 1;\n-\t\t\telse\n-\t\t\t\tptr++;\n+\t\t\t\treturn ptr;\n \t\t}\n \t\treturn ptr;\n \t}\n-- \n1.6.1.rc2.299.gead4c\n"},{"id":"97526","messageId":"1228946751-12708-4-git-send-email-spearce@spearce.org","threadId":"16674","inReplyTo":"1228946751-12708-3-git-send-email-spearce@spearce.org","subject":"[JGIT PATCH 3/6] Correct Javadoc of RawParseUtils next and nextLF methods","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2008-12-10T22:05:48Z","receivedAt":"2008-12-10T22:05:48Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Signed-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n .../src/org/spearce/jgit/util/RawParseUtils.java   |    8 ++++----\n 1 files changed, 4 insertions(+), 4 deletions(-)\n\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/util/RawParseUtils.java b/org.spearce.jgit/src/org/spearce/jgit/util/RawParseUtils.java\nindex 5a40911..8896d38 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/util/RawParseUtils.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/util/RawParseUtils.java\n@@ -213,10 +213,10 @@ public static final int parseTimeZoneOffset(final byte[] b, int ptr) {\n \t * @param b\n \t *            buffer to scan.\n \t * @param ptr\n-\t *            position within buffer to start looking for LF at.\n+\t *            position within buffer to start looking for chrA at.\n \t * @param chrA\n \t *            character to find.\n-\t * @return new position just after chr.\n+\t * @return new position just after chrA.\n \t */\n \tpublic static final int next(final byte[] b, int ptr, final char chrA) {\n \t\tfinal int sz = b.length;\n@@ -250,10 +250,10 @@ public static final int nextLF(final byte[] b, int ptr) {\n \t * @param b\n \t *            buffer to scan.\n \t * @param ptr\n-\t *            position within buffer to start looking for LF at.\n+\t *            position within buffer to start looking for chrA or LF at.\n \t * @param chrA\n \t *            character to find.\n-\t * @return new position just after the first chrA or chrB to be found.\n+\t * @return new position just after the first chrA or LF to be found.\n \t */\n \tpublic static final int nextLF(final byte[] b, int ptr, final char chrA) {\n \t\tfinal int sz = b.length;\n-- \n1.6.1.rc2.299.gead4c\n"},{"id":"97527","messageId":"1228946751-12708-5-git-send-email-spearce@spearce.org","threadId":"16674","inReplyTo":"1228946751-12708-4-git-send-email-spearce@spearce.org","subject":"[JGIT PATCH 4/6] Add QuotedString class to handle C-style quoting rules","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2008-12-10T22:05:49Z","receivedAt":"2008-12-10T22:05:49Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Git patch files can contain file names which are quoted using the\nC language quoting rules.  In order to correctly create or parse\nthese files we must implement a quoting style that matches those\nspecific rules.\n\nQuotedString itself is an abstract API so callers can be passed a\nquoting style based on the context of where their output will be\nused, and multiple styles could be supported.  This may be useful\nif jgit ever grows a \"git for-each-ref\" style of output where Perl,\nPython, Tcl and Bourne style quoting might be necessary.\n\nReferences through the singleton QuotedString.C should be able to\nbypass the virtual function table, as the specific type is mentioned\nin the field declaration and that type is final.  A good JIT should\nbe able to remove the abstraction costs when the caller has hardcoded\nthe quoting style.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n .../spearce/jgit/util/QuotedStringC_StyleTest.java |  144 +++++++++++\n .../src/org/spearce/jgit/util/QuotedString.java    |  270 ++++++++++++++++++++\n 2 files changed, 414 insertions(+), 0 deletions(-)\n create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/util/QuotedStringC_StyleTest.java\n create mode 100644 org.spearce.jgit/src/org/spearce/jgit/util/QuotedString.java\n\ndiff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/util/QuotedStringC_StyleTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/util/QuotedStringC_StyleTest.java\nnew file mode 100644\nindex 0000000..493869c\n--- /dev/null\n+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/util/QuotedStringC_StyleTest.java\n@@ -0,0 +1,144 @@\n+/*\n+ * Copyright (C) 2008, Google Inc.\n+ *\n+ * All rights reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or\n+ * without modification, are permitted provided that the following\n+ * conditions are met:\n+ *\n+ * - Redistributions of source code must retain the above copyright\n+ *   notice, this list of conditions and the following disclaimer.\n+ *\n+ * - Redistributions in binary form must reproduce the above\n+ *   copyright notice, this list of conditions and the following\n+ *   disclaimer in the documentation and/or other materials provided\n+ *   with the distribution.\n+ *\n+ * - Neither the name of the Git Development Community nor the\n+ *   names of its contributors may be used to endorse or promote\n+ *   products derived from this software without specific prior\n+ *   written permission.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND\n+ * CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES,\n+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\n+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\n+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\n+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+\n+package org.spearce.jgit.util;\n+\n+import static org.spearce.jgit.util.QuotedString.C;\n+import junit.framework.TestCase;\n+\n+import org.spearce.jgit.lib.Constants;\n+\n+public class QuotedStringC_StyleTest extends TestCase {\n+\tprivate static void assertQuote(final String in, final String exp) {\n+\t\tfinal String r = C.quote(in);\n+\t\tassertNotSame(in, r);\n+\t\tassertFalse(in.equals(r));\n+\t\tassertEquals('\"' + exp + '\"', r);\n+\t}\n+\n+\tprivate static void assertDequote(final String exp, final String in) {\n+\t\tfinal byte[] b = Constants.encode('\"' + in + '\"');\n+\t\tfinal String r = C.dequote(b, 0, b.length);\n+\t\tassertEquals(exp, r);\n+\t}\n+\n+\tpublic void testQuote_Empty() {\n+\t\tassertEquals(\"\\\"\\\"\", C.quote(\"\"));\n+\t}\n+\n+\tpublic void testDequote_Empty1() {\n+\t\tassertEquals(\"\", C.dequote(new byte[0], 0, 0));\n+\t}\n+\n+\tpublic void testDequote_Empty2() {\n+\t\tassertEquals(\"\", C.dequote(new byte[] { '\"', '\"' }, 0, 2));\n+\t}\n+\n+\tpublic void testDequote_SoleDq() {\n+\t\tassertEquals(\"\\\"\", C.dequote(new byte[] { '\"' }, 0, 1));\n+\t}\n+\n+\tpublic void testQuote_BareA() {\n+\t\tfinal String in = \"a\";\n+\t\tassertSame(in, C.quote(in));\n+\t}\n+\n+\tpublic void testDequote_BareA() {\n+\t\tfinal String in = \"a\";\n+\t\tfinal byte[] b = Constants.encode(in);\n+\t\tassertEquals(in, C.dequote(b, 0, b.length));\n+\t}\n+\n+\tpublic void testDequote_BareABCZ_OnlyBC() {\n+\t\tfinal String in = \"abcz\";\n+\t\tfinal byte[] b = Constants.encode(in);\n+\t\tfinal int p = in.indexOf('b');\n+\t\tassertEquals(\"bc\", C.dequote(b, p, p + 2));\n+\t}\n+\n+\tpublic void testDequote_LoneBackslash() {\n+\t\tassertDequote(\"\\\\\", \"\\\\\");\n+\t}\n+\n+\tpublic void testQuote_NamedEscapes() {\n+\t\tassertQuote(\"\\u0007\", \"\\\\a\");\n+\t\tassertQuote(\"\\b\", \"\\\\b\");\n+\t\tassertQuote(\"\\f\", \"\\\\f\");\n+\t\tassertQuote(\"\\n\", \"\\\\n\");\n+\t\tassertQuote(\"\\r\", \"\\\\r\");\n+\t\tassertQuote(\"\\t\", \"\\\\t\");\n+\t\tassertQuote(\"\\u000B\", \"\\\\v\");\n+\t\tassertQuote(\"\\\\\", \"\\\\\\\\\");\n+\t\tassertQuote(\"\\\"\", \"\\\\\\\"\");\n+\t}\n+\n+\tpublic void testDequote_NamedEscapes() {\n+\t\tassertDequote(\"\\u0007\", \"\\\\a\");\n+\t\tassertDequote(\"\\b\", \"\\\\b\");\n+\t\tassertDequote(\"\\f\", \"\\\\f\");\n+\t\tassertDequote(\"\\n\", \"\\\\n\");\n+\t\tassertDequote(\"\\r\", \"\\\\r\");\n+\t\tassertDequote(\"\\t\", \"\\\\t\");\n+\t\tassertDequote(\"\\u000B\", \"\\\\v\");\n+\t\tassertDequote(\"\\\\\", \"\\\\\\\\\");\n+\t\tassertDequote(\"\\\"\", \"\\\\\\\"\");\n+\t}\n+\n+\tpublic void testDequote_OctalAll() {\n+\t\tfor (int i = 0; i < 256; i++) {\n+\t\t\tString s = Integer.toOctalString(i);\n+\t\t\twhile (s.length() < 3) {\n+\t\t\t\ts = \"0\" + s;\n+\t\t\t}\n+\t\t\tassertDequote(\"\" + (char) i, \"\\\\\" + s);\n+\t\t}\n+\t}\n+\n+\tpublic void testQuote_OctalAll() {\n+\t\tassertQuote(\"\\1\", \"\\\\001\");\n+\t\tassertQuote(\"~\", \"\\\\176\");\n+\t\tassertQuote(\"\\u00ff\", \"\\\\303\\\\277\"); // \\u00ff in UTF-8\n+\t}\n+\n+\tpublic void testDequote_UnknownEscapeQ() {\n+\t\tassertDequote(\"\\\\q\", \"\\\\q\");\n+\t}\n+\n+\tpublic void testDequote_FooTabBar() {\n+\t\tassertDequote(\"foo\\tbar\", \"foo\\\\tbar\");\n+\t}\n+}\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/util/QuotedString.java b/org.spearce.jgit/src/org/spearce/jgit/util/QuotedString.java\nnew file mode 100644\nindex 0000000..4aaa8ff\n--- /dev/null\n+++ b/org.spearce.jgit/src/org/spearce/jgit/util/QuotedString.java\n@@ -0,0 +1,270 @@\n+/*\n+ * Copyright (C) 2008, Google Inc.\n+ *\n+ * All rights reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or\n+ * without modification, are permitted provided that the following\n+ * conditions are met:\n+ *\n+ * - Redistributions of source code must retain the above copyright\n+ *   notice, this list of conditions and the following disclaimer.\n+ *\n+ * - Redistributions in binary form must reproduce the above\n+ *   copyright notice, this list of conditions and the following\n+ *   disclaimer in the documentation and/or other materials provided\n+ *   with the distribution.\n+ *\n+ * - Neither the name of the Git Development Community nor the\n+ *   names of its contributors may be used to endorse or promote\n+ *   products derived from this software without specific prior\n+ *   written permission.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND\n+ * CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES,\n+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\n+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\n+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\n+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+\n+package org.spearce.jgit.util;\n+\n+import static org.spearce.jgit.util.RawParseUtils.decode;\n+\n+import java.util.Arrays;\n+\n+import org.spearce.jgit.lib.Constants;\n+\n+/** Utility functions related to quoted string handling. */\n+public abstract class QuotedString {\n+\t/** Quoting style that obeys the rules of the C programming language. */\n+\tpublic static final C_Style C = new C_Style();\n+\n+\t/**\n+\t * Quote an input string by the quoting rules.\n+\t * <p>\n+\t * If the input string does not require any quoting, the same String\n+\t * reference is returned to the caller.\n+\t * <p>\n+\t * Otherwise a quoted string is returned, including the opening and closing\n+\t * quotation marks at the start and end of the string. If the style does not\n+\t * permit raw Unicode characters then the string will first be encoded in\n+\t * UTF-8, with unprintable sequences possibly escaped by the rules.\n+\t * \n+\t * @param in\n+\t *            any non-null Unicode string.\n+\t * @return a quoted string. See above for details.\n+\t */\n+\tpublic abstract String quote(String in);\n+\n+\t/**\n+\t * Clean a previously quoted input, decoding the result via UTF-8.\n+\t * <p>\n+\t * This method must match quote such that:\n+\t * \n+\t * <pre>\n+\t * a.equals(dequote(quote(a)));\n+\t * </pre>\n+\t * \n+\t * is true for any <code>a</code>.\n+\t * \n+\t * @param in\n+\t *            a Unicode string to remove quoting from.\n+\t * @return the cleaned string.\n+\t * @see #dequote(byte[], int, int)\n+\t */\n+\tpublic String dequote(final String in) {\n+\t\tfinal byte[] b = Constants.encode(in);\n+\t\treturn dequote(b, 0, b.length);\n+\t}\n+\n+\t/**\n+\t * Decode a previously quoted input, scanning a UTF-8 encoded buffer.\n+\t * <p>\n+\t * This method must match quote such that:\n+\t * \n+\t * <pre>\n+\t * a.equals(dequote(Constants.encode(quote(a))));\n+\t * </pre>\n+\t * \n+\t * is true for any <code>a</code>.\n+\t * <p>\n+\t * This method removes any opening/closing quotation marks added by\n+\t * {@link #quote(String)}.\n+\t * \n+\t * @param in\n+\t *            the input buffer to parse.\n+\t * @param offset\n+\t *            first position within <code>in</code> to scan.\n+\t * @param end\n+\t *            one position past in <code>in</code> to scan.\n+\t * @return the cleaned string.\n+\t */\n+\tpublic abstract String dequote(byte[] in, int offset, int end);\n+\n+\t/** Quoting style that obeys the rules of the C programming language. */\n+\tpublic static final class C_Style extends QuotedString {\n+\t\tprivate static final byte[] quote;\n+\t\tstatic {\n+\t\t\tquote = new byte[128];\n+\t\t\tArrays.fill(quote, (byte) -1);\n+\n+\t\t\tfor (int i = '0'; i <= '9'; i++)\n+\t\t\t\tquote[i] = 0;\n+\t\t\tfor (int i = 'a'; i <= 'z'; i++)\n+\t\t\t\tquote[i] = 0;\n+\t\t\tfor (int i = 'A'; i <= 'Z'; i++)\n+\t\t\t\tquote[i] = 0;\n+\t\t\tquote[' '] = 0;\n+\t\t\tquote['+'] = 0;\n+\t\t\tquote[','] = 0;\n+\t\t\tquote['-'] = 0;\n+\t\t\tquote['.'] = 0;\n+\t\t\tquote['/'] = 0;\n+\t\t\tquote['='] = 0;\n+\t\t\tquote['_'] = 0;\n+\t\t\tquote['^'] = 0;\n+\n+\t\t\tquote['\\u0007'] = 'a';\n+\t\t\tquote['\\b'] = 'b';\n+\t\t\tquote['\\f'] = 'f';\n+\t\t\tquote['\\n'] = 'n';\n+\t\t\tquote['\\r'] = 'r';\n+\t\t\tquote['\\t'] = 't';\n+\t\t\tquote['\\u000B'] = 'v';\n+\t\t\tquote['\\\\'] = '\\\\';\n+\t\t\tquote['\"'] = '\"';\n+\t\t}\n+\n+\t\t@Override\n+\t\tpublic String quote(final String instr) {\n+\t\t\tif (instr.length() == 0)\n+\t\t\t\treturn \"\\\"\\\"\";\n+\t\t\tboolean reuse = true;\n+\t\t\tfinal byte[] in = Constants.encode(instr);\n+\t\t\tfinal StringBuilder r = new StringBuilder(2 + in.length);\n+\t\t\tr.append('\"');\n+\t\t\tfor (int i = 0; i < in.length; i++) {\n+\t\t\t\tfinal int c = in[i] & 0xff;\n+\t\t\t\tif (c < quote.length) {\n+\t\t\t\t\tfinal byte style = quote[c];\n+\t\t\t\t\tif (style == 0) {\n+\t\t\t\t\t\tr.append((char) c);\n+\t\t\t\t\t\tcontinue;\n+\t\t\t\t\t}\n+\t\t\t\t\tif (style > 0) {\n+\t\t\t\t\t\treuse = false;\n+\t\t\t\t\t\tr.append('\\\\');\n+\t\t\t\t\t\tr.append((char) style);\n+\t\t\t\t\t\tcontinue;\n+\t\t\t\t\t}\n+\t\t\t\t}\n+\n+\t\t\t\treuse = false;\n+\t\t\t\tr.append('\\\\');\n+\t\t\t\tr.append((char) (((c >> 6) & 03) + '0'));\n+\t\t\t\tr.append((char) (((c >> 3) & 07) + '0'));\n+\t\t\t\tr.append((char) (((c >> 0) & 07) + '0'));\n+\t\t\t}\n+\t\t\tif (reuse)\n+\t\t\t\treturn instr;\n+\t\t\tr.append('\"');\n+\t\t\treturn r.toString();\n+\t\t}\n+\n+\t\t@Override\n+\t\tpublic String dequote(final byte[] in, final int inPtr, final int inEnd) {\n+\t\t\tif (2 <= inEnd - inPtr && in[inPtr] == '\"' && in[inEnd - 1] == '\"')\n+\t\t\t\treturn dq(in, inPtr + 1, inEnd - 1);\n+\t\t\treturn decode(Constants.CHARSET, in, inPtr, inEnd);\n+\t\t}\n+\n+\t\tprivate static String dq(final byte[] in, int inPtr, final int inEnd) {\n+\t\t\tfinal byte[] r = new byte[inEnd - inPtr];\n+\t\t\tint rPtr = 0;\n+\t\t\twhile (inPtr < inEnd) {\n+\t\t\t\tfinal byte b = in[inPtr++];\n+\t\t\t\tif (b != '\\\\') {\n+\t\t\t\t\tr[rPtr++] = b;\n+\t\t\t\t\tcontinue;\n+\t\t\t\t}\n+\n+\t\t\t\tif (inPtr == inEnd) {\n+\t\t\t\t\t// Lone trailing backslash. Treat it as a literal.\n+\t\t\t\t\t//\n+\t\t\t\t\tr[rPtr++] = '\\\\';\n+\t\t\t\t\tbreak;\n+\t\t\t\t}\n+\n+\t\t\t\tswitch (in[inPtr++]) {\n+\t\t\t\tcase 'a':\n+\t\t\t\t\tr[rPtr++] = 0x07 /* \\a = BEL */;\n+\t\t\t\t\tcontinue;\n+\t\t\t\tcase 'b':\n+\t\t\t\t\tr[rPtr++] = '\\b';\n+\t\t\t\t\tcontinue;\n+\t\t\t\tcase 'f':\n+\t\t\t\t\tr[rPtr++] = '\\f';\n+\t\t\t\t\tcontinue;\n+\t\t\t\tcase 'n':\n+\t\t\t\t\tr[rPtr++] = '\\n';\n+\t\t\t\t\tcontinue;\n+\t\t\t\tcase 'r':\n+\t\t\t\t\tr[rPtr++] = '\\r';\n+\t\t\t\t\tcontinue;\n+\t\t\t\tcase 't':\n+\t\t\t\t\tr[rPtr++] = '\\t';\n+\t\t\t\t\tcontinue;\n+\t\t\t\tcase 'v':\n+\t\t\t\t\tr[rPtr++] = 0x0B/* \\v = VT */;\n+\t\t\t\t\tcontinue;\n+\n+\t\t\t\tcase '\\\\':\n+\t\t\t\tcase '\"':\n+\t\t\t\t\tr[rPtr++] = in[inPtr - 1];\n+\t\t\t\t\tcontinue;\n+\n+\t\t\t\tcase '0':\n+\t\t\t\tcase '1':\n+\t\t\t\tcase '2':\n+\t\t\t\tcase '3': {\n+\t\t\t\t\tint cp = in[inPtr - 1] - '0';\n+\t\t\t\t\twhile (inPtr < inEnd) {\n+\t\t\t\t\t\tfinal byte c = in[inPtr];\n+\t\t\t\t\t\tif ('0' <= c && c <= '7') {\n+\t\t\t\t\t\t\tcp <<= 3;\n+\t\t\t\t\t\t\tcp |= c - '0';\n+\t\t\t\t\t\t\tinPtr++;\n+\t\t\t\t\t\t} else {\n+\t\t\t\t\t\t\tbreak;\n+\t\t\t\t\t\t}\n+\t\t\t\t\t}\n+\t\t\t\t\tr[rPtr++] = (byte) cp;\n+\t\t\t\t\tcontinue;\n+\t\t\t\t}\n+\n+\t\t\t\tdefault:\n+\t\t\t\t\t// Any other code is taken literally.\n+\t\t\t\t\t//\n+\t\t\t\t\tr[rPtr++] = '\\\\';\n+\t\t\t\t\tr[rPtr++] = in[inPtr - 1];\n+\t\t\t\t\tcontinue;\n+\t\t\t\t}\n+\t\t\t}\n+\n+\t\t\treturn decode(Constants.CHARSET, r, 0, rPtr);\n+\t\t}\n+\n+\t\tprivate C_Style() {\n+\t\t\t// Singleton\n+\t\t}\n+\t}\n+}\n-- \n1.6.1.rc2.299.gead4c\n"},{"id":"97530","messageId":"1228946751-12708-6-git-send-email-spearce@spearce.org","threadId":"16674","inReplyTo":"1228946751-12708-5-git-send-email-spearce@spearce.org","subject":"[JGIT PATCH 5/6] Add Bourne style quoting for TransportGitSsh","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2008-12-10T22:05:50Z","receivedAt":"2008-12-10T22:05:50Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Now that we have a nice QuotedString abstraction we can port our\nstring quoting logic from being private within the SSH transport\ncode to being available in the rest of the library.\n\nCurrently we only support the super-restrictive quoting style used\nfor the repository path name argument over SSH.  We don't support the\n\"minimal\" style used to invoke the command name, nor do we support\nthe ~user/ style format, which cannot be quoted.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n .../jgit/util/QuotedStringBourneStyleTest.java     |  111 ++++++++++++++++++++\n .../spearce/jgit/transport/TransportGitSsh.java    |   13 +--\n .../src/org/spearce/jgit/util/QuotedString.java    |   66 ++++++++++++\n 3 files changed, 179 insertions(+), 11 deletions(-)\n create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/util/QuotedStringBourneStyleTest.java\n\ndiff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/util/QuotedStringBourneStyleTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/util/QuotedStringBourneStyleTest.java\nnew file mode 100644\nindex 0000000..86d46fe\n--- /dev/null\n+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/util/QuotedStringBourneStyleTest.java\n@@ -0,0 +1,111 @@\n+/*\n+ * Copyright (C) 2008, Google Inc.\n+ *\n+ * All rights reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or\n+ * without modification, are permitted provided that the following\n+ * conditions are met:\n+ *\n+ * - Redistributions of source code must retain the above copyright\n+ *   notice, this list of conditions and the following disclaimer.\n+ *\n+ * - Redistributions in binary form must reproduce the above\n+ *   copyright notice, this list of conditions and the following\n+ *   disclaimer in the documentation and/or other materials provided\n+ *   with the distribution.\n+ *\n+ * - Neither the name of the Git Development Community nor the\n+ *   names of its contributors may be used to endorse or promote\n+ *   products derived from this software without specific prior\n+ *   written permission.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND\n+ * CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES,\n+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\n+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\n+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\n+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+\n+package org.spearce.jgit.util;\n+\n+import static org.spearce.jgit.util.QuotedString.BOURNE;\n+import junit.framework.TestCase;\n+\n+import org.spearce.jgit.lib.Constants;\n+\n+public class QuotedStringBourneStyleTest extends TestCase {\n+\tprivate static void assertQuote(final String in, final String exp) {\n+\t\tfinal String r = BOURNE.quote(in);\n+\t\tassertNotSame(in, r);\n+\t\tassertFalse(in.equals(r));\n+\t\tassertEquals('\\'' + exp + '\\'', r);\n+\t}\n+\n+\tprivate static void assertDequote(final String exp, final String in) {\n+\t\tfinal byte[] b = Constants.encode('\\'' + in + '\\'');\n+\t\tfinal String r = BOURNE.dequote(b, 0, b.length);\n+\t\tassertEquals(exp, r);\n+\t}\n+\n+\tpublic void testQuote_Empty() {\n+\t\tassertEquals(\"''\", BOURNE.quote(\"\"));\n+\t}\n+\n+\tpublic void testDequote_Empty1() {\n+\t\tassertEquals(\"\", BOURNE.dequote(new byte[0], 0, 0));\n+\t}\n+\n+\tpublic void testDequote_Empty2() {\n+\t\tassertEquals(\"\", BOURNE.dequote(new byte[] { '\\'', '\\'' }, 0, 2));\n+\t}\n+\n+\tpublic void testDequote_SoleSq() {\n+\t\tassertEquals(\"\", BOURNE.dequote(new byte[] { '\\'' }, 0, 1));\n+\t}\n+\n+\tpublic void testQuote_BareA() {\n+\t\tassertQuote(\"a\", \"a\");\n+\t}\n+\n+\tpublic void testDequote_BareA() {\n+\t\tfinal String in = \"a\";\n+\t\tfinal byte[] b = Constants.encode(in);\n+\t\tassertEquals(in, BOURNE.dequote(b, 0, b.length));\n+\t}\n+\n+\tpublic void testDequote_BareABCZ_OnlyBC() {\n+\t\tfinal String in = \"abcz\";\n+\t\tfinal byte[] b = Constants.encode(in);\n+\t\tfinal int p = in.indexOf('b');\n+\t\tassertEquals(\"bc\", BOURNE.dequote(b, p, p + 2));\n+\t}\n+\n+\tpublic void testDequote_LoneBackslash() {\n+\t\tassertDequote(\"\\\\\", \"\\\\\");\n+\t}\n+\n+\tpublic void testQuote_NamedEscapes() {\n+\t\tassertQuote(\"'\", \"'\\\\''\");\n+\t\tassertQuote(\"!\", \"'\\\\!'\");\n+\n+\t\tassertQuote(\"a'b\", \"a'\\\\''b\");\n+\t\tassertQuote(\"a!b\", \"a'\\\\!'b\");\n+\t}\n+\n+\tpublic void testDequote_NamedEscapes() {\n+\t\tassertDequote(\"'\", \"'\\\\''\");\n+\t\tassertDequote(\"!\", \"'\\\\!'\");\n+\n+\t\tassertDequote(\"a'b\", \"a'\\\\''b\");\n+\t\tassertDequote(\"a!b\", \"a'\\\\!'b\");\n+\t}\n+}\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/TransportGitSsh.java b/org.spearce.jgit/src/org/spearce/jgit/transport/TransportGitSsh.java\nindex 3f2cd37..e3f5ae8 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/transport/TransportGitSsh.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/transport/TransportGitSsh.java\n@@ -47,6 +47,7 @@\n import org.spearce.jgit.errors.NoRemoteRepositoryException;\n import org.spearce.jgit.errors.TransportException;\n import org.spearce.jgit.lib.Repository;\n+import org.spearce.jgit.util.QuotedString;\n \n import com.jcraft.jsch.ChannelExec;\n import com.jcraft.jsch.JSchException;\n@@ -154,17 +155,7 @@ private static void sq(final StringBuilder cmd, final String val) {\n \t\t\t\treturn;\n \t\t}\n \n-\t\tcmd.append('\\'');\n-\t\tfor (; i < val.length(); i++) {\n-\t\t\tfinal char c = val.charAt(i);\n-\t\t\tif (c == '\\'')\n-\t\t\t\tcmd.append(\"'\\\\''\");\n-\t\t\telse if (c == '!')\n-\t\t\t\tcmd.append(\"'\\\\!'\");\n-\t\t\telse\n-\t\t\t\tcmd.append(c);\n-\t\t}\n-\t\tcmd.append('\\'');\n+\t\tcmd.append(QuotedString.BOURNE.quote(val.substring(i)));\n \t}\n \n \tprivate void initSession() throws TransportException {\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/util/QuotedString.java b/org.spearce.jgit/src/org/spearce/jgit/util/QuotedString.java\nindex 4aaa8ff..1089e9e 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/util/QuotedString.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/util/QuotedString.java\n@@ -49,6 +49,15 @@\n \tpublic static final C_Style C = new C_Style();\n \n \t/**\n+\t * Quoting style used by the Bourne shell.\n+\t * <p>\n+\t * Quotes are unconditionally inserted during {@link #quote(String)}. This\n+\t * protects shell meta-characters like <code>$</code> or <code>~</code> from\n+\t * being recognized as special.\n+\t */\n+\tpublic static final BourneStyle BOURNE = new BourneStyle();\n+\n+\t/**\n \t * Quote an input string by the quoting rules.\n \t * <p>\n \t * If the input string does not require any quoting, the same String\n@@ -110,6 +119,63 @@ public String dequote(final String in) {\n \t */\n \tpublic abstract String dequote(byte[] in, int offset, int end);\n \n+\t/**\n+\t * Quoting style used by the Bourne shell.\n+\t * <p>\n+\t * Quotes are unconditionally inserted during {@link #quote(String)}. This\n+\t * protects shell meta-characters like <code>$</code> or <code>~</code> from\n+\t * being recognized as special.\n+\t */\n+\tpublic static class BourneStyle extends QuotedString {\n+\t\t@Override\n+\t\tpublic String quote(final String in) {\n+\t\t\tfinal StringBuilder r = new StringBuilder();\n+\t\t\tr.append('\\'');\n+\t\t\tint start = 0, i = 0;\n+\t\t\tfor (; i < in.length(); i++) {\n+\t\t\t\tswitch (in.charAt(i)) {\n+\t\t\t\tcase '\\'':\n+\t\t\t\tcase '!':\n+\t\t\t\t\tr.append(in, start, i);\n+\t\t\t\t\tr.append('\\'');\n+\t\t\t\t\tr.append('\\\\');\n+\t\t\t\t\tr.append(in.charAt(i));\n+\t\t\t\t\tr.append('\\'');\n+\t\t\t\t\tstart = i + 1;\n+\t\t\t\t\tbreak;\n+\t\t\t\t}\n+\t\t\t}\n+\t\t\tr.append(in, start, i);\n+\t\t\tr.append('\\'');\n+\t\t\treturn r.toString();\n+\t\t}\n+\n+\t\t@Override\n+\t\tpublic String dequote(final byte[] in, int ip, final int ie) {\n+\t\t\tboolean inquote = false;\n+\t\t\tfinal byte[] r = new byte[ie - ip];\n+\t\t\tint rPtr = 0;\n+\t\t\twhile (ip < ie) {\n+\t\t\t\tfinal byte b = in[ip++];\n+\t\t\t\tswitch (b) {\n+\t\t\t\tcase '\\'':\n+\t\t\t\t\tinquote = !inquote;\n+\t\t\t\t\tcontinue;\n+\t\t\t\tcase '\\\\':\n+\t\t\t\t\tif (inquote || ip == ie)\n+\t\t\t\t\t\tr[rPtr++] = b; // literal within a quote\n+\t\t\t\t\telse\n+\t\t\t\t\t\tr[rPtr++] = in[ip++];\n+\t\t\t\t\tcontinue;\n+\t\t\t\tdefault:\n+\t\t\t\t\tr[rPtr++] = b;\n+\t\t\t\t\tcontinue;\n+\t\t\t\t}\n+\t\t\t}\n+\t\t\treturn decode(Constants.CHARSET, r, 0, rPtr);\n+\t\t}\n+\t}\n+\n \t/** Quoting style that obeys the rules of the C programming language. */\n \tpublic static final class C_Style extends QuotedString {\n \t\tprivate static final byte[] quote;\n-- \n1.6.1.rc2.299.gead4c\n"},{"id":"97524","messageId":"1228946751-12708-7-git-send-email-spearce@spearce.org","threadId":"16674","inReplyTo":"1228946751-12708-6-git-send-email-spearce@spearce.org","subject":"[JGIT PATCH 6/6] Add ~user friendly Bourne style quoting for TransportGitSsh","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2008-12-10T22:05:51Z","receivedAt":"2008-12-10T22:05:51Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"This mostly completes the migration of our quoting rules from the\nSSH transport to our QuotedString pattern.  User names may be left\nalone for the shell to expand when the string is evaluated, if the\ncaller wants that sort of behavior in a particular context.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n .../util/QuotedStringBourneUserPathStyleTest.java  |  130 ++++++++++++++++++++\n .../spearce/jgit/transport/TransportGitSsh.java    |   27 +----\n .../src/org/spearce/jgit/util/QuotedString.java    |   28 ++++\n 3 files changed, 160 insertions(+), 25 deletions(-)\n create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/util/QuotedStringBourneUserPathStyleTest.java\n\ndiff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/util/QuotedStringBourneUserPathStyleTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/util/QuotedStringBourneUserPathStyleTest.java\nnew file mode 100644\nindex 0000000..36fb52a\n--- /dev/null\n+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/util/QuotedStringBourneUserPathStyleTest.java\n@@ -0,0 +1,130 @@\n+/*\n+ * Copyright (C) 2008, Google Inc.\n+ *\n+ * All rights reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or\n+ * without modification, are permitted provided that the following\n+ * conditions are met:\n+ *\n+ * - Redistributions of source code must retain the above copyright\n+ *   notice, this list of conditions and the following disclaimer.\n+ *\n+ * - Redistributions in binary form must reproduce the above\n+ *   copyright notice, this list of conditions and the following\n+ *   disclaimer in the documentation and/or other materials provided\n+ *   with the distribution.\n+ *\n+ * - Neither the name of the Git Development Community nor the\n+ *   names of its contributors may be used to endorse or promote\n+ *   products derived from this software without specific prior\n+ *   written permission.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND\n+ * CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES,\n+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\n+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\n+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\n+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+\n+package org.spearce.jgit.util;\n+\n+import static org.spearce.jgit.util.QuotedString.BOURNE_USER_PATH;\n+import junit.framework.TestCase;\n+\n+import org.spearce.jgit.lib.Constants;\n+\n+public class QuotedStringBourneUserPathStyleTest extends TestCase {\n+\tprivate static void assertQuote(final String in, final String exp) {\n+\t\tfinal String r = BOURNE_USER_PATH.quote(in);\n+\t\tassertNotSame(in, r);\n+\t\tassertFalse(in.equals(r));\n+\t\tassertEquals('\\'' + exp + '\\'', r);\n+\t}\n+\n+\tprivate static void assertDequote(final String exp, final String in) {\n+\t\tfinal byte[] b = Constants.encode('\\'' + in + '\\'');\n+\t\tfinal String r = BOURNE_USER_PATH.dequote(b, 0, b.length);\n+\t\tassertEquals(exp, r);\n+\t}\n+\n+\tpublic void testQuote_Empty() {\n+\t\tassertEquals(\"''\", BOURNE_USER_PATH.quote(\"\"));\n+\t}\n+\n+\tpublic void testDequote_Empty1() {\n+\t\tassertEquals(\"\", BOURNE_USER_PATH.dequote(new byte[0], 0, 0));\n+\t}\n+\n+\tpublic void testDequote_Empty2() {\n+\t\tassertEquals(\"\", BOURNE_USER_PATH.dequote(new byte[] { '\\'', '\\'' }, 0,\n+\t\t\t\t2));\n+\t}\n+\n+\tpublic void testDequote_SoleSq() {\n+\t\tassertEquals(\"\", BOURNE_USER_PATH.dequote(new byte[] { '\\'' }, 0, 1));\n+\t}\n+\n+\tpublic void testQuote_BareA() {\n+\t\tassertQuote(\"a\", \"a\");\n+\t}\n+\n+\tpublic void testDequote_BareA() {\n+\t\tfinal String in = \"a\";\n+\t\tfinal byte[] b = Constants.encode(in);\n+\t\tassertEquals(in, BOURNE_USER_PATH.dequote(b, 0, b.length));\n+\t}\n+\n+\tpublic void testDequote_BareABCZ_OnlyBC() {\n+\t\tfinal String in = \"abcz\";\n+\t\tfinal byte[] b = Constants.encode(in);\n+\t\tfinal int p = in.indexOf('b');\n+\t\tassertEquals(\"bc\", BOURNE_USER_PATH.dequote(b, p, p + 2));\n+\t}\n+\n+\tpublic void testDequote_LoneBackslash() {\n+\t\tassertDequote(\"\\\\\", \"\\\\\");\n+\t}\n+\n+\tpublic void testQuote_NamedEscapes() {\n+\t\tassertQuote(\"'\", \"'\\\\''\");\n+\t\tassertQuote(\"!\", \"'\\\\!'\");\n+\n+\t\tassertQuote(\"a'b\", \"a'\\\\''b\");\n+\t\tassertQuote(\"a!b\", \"a'\\\\!'b\");\n+\t}\n+\n+\tpublic void testDequote_NamedEscapes() {\n+\t\tassertDequote(\"'\", \"'\\\\''\");\n+\t\tassertDequote(\"!\", \"'\\\\!'\");\n+\n+\t\tassertDequote(\"a'b\", \"a'\\\\''b\");\n+\t\tassertDequote(\"a!b\", \"a'\\\\!'b\");\n+\t}\n+\n+\tpublic void testQuote_User() {\n+\t\tassertEquals(\"~foo/\", BOURNE_USER_PATH.quote(\"~foo\"));\n+\t\tassertEquals(\"~foo/\", BOURNE_USER_PATH.quote(\"~foo/\"));\n+\t\tassertEquals(\"~/\", BOURNE_USER_PATH.quote(\"~/\"));\n+\n+\t\tassertEquals(\"~foo/'a'\", BOURNE_USER_PATH.quote(\"~foo/a\"));\n+\t\tassertEquals(\"~/'a'\", BOURNE_USER_PATH.quote(\"~/a\"));\n+\t}\n+\n+\tpublic void testDequote_User() {\n+\t\tassertEquals(\"~foo\", BOURNE_USER_PATH.dequote(\"~foo\"));\n+\t\tassertEquals(\"~foo/\", BOURNE_USER_PATH.dequote(\"~foo/\"));\n+\t\tassertEquals(\"~/\", BOURNE_USER_PATH.dequote(\"~/\"));\n+\n+\t\tassertEquals(\"~foo/a\", BOURNE_USER_PATH.dequote(\"~foo/'a'\"));\n+\t\tassertEquals(\"~/a\", BOURNE_USER_PATH.dequote(\"~/'a'\"));\n+\t}\n+}\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/TransportGitSsh.java b/org.spearce.jgit/src/org/spearce/jgit/transport/TransportGitSsh.java\nindex e3f5ae8..d4bf466 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/transport/TransportGitSsh.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/transport/TransportGitSsh.java\n@@ -131,31 +131,8 @@ private static void sqAlways(final StringBuilder cmd, final String val) {\n \t}\n \n \tprivate static void sq(final StringBuilder cmd, final String val) {\n-\t\tint i = 0;\n-\n-\t\tif (val.length() == 0)\n-\t\t\treturn;\n-\t\tif (val.matches(\"^~[A-Za-z0-9_-]+$\")) {\n-\t\t\t// If the string is just \"~user\" we can assume they\n-\t\t\t// mean \"~user/\" and evaluate it within the shell.\n-\t\t\t//\n-\t\t\tcmd.append(val);\n-\t\t\tcmd.append('/');\n-\t\t\treturn;\n-\t\t}\n-\n-\t\tif (val.matches(\"^~[A-Za-z0-9_-]*/.*$\")) {\n-\t\t\t// If the string is of \"~/path\" or \"~user/path\"\n-\t\t\t// we must not escape ~/ or ~user/ from the shell\n-\t\t\t// as we need that portion to be evaluated.\n-\t\t\t//\n-\t\t\ti = val.indexOf('/') + 1;\n-\t\t\tcmd.append(val.substring(0, i));\n-\t\t\tif (i == val.length())\n-\t\t\t\treturn;\n-\t\t}\n-\n-\t\tcmd.append(QuotedString.BOURNE.quote(val.substring(i)));\n+\t\tif (val.length() > 0)\n+\t\t\tcmd.append(QuotedString.BOURNE.quote(val));\n \t}\n \n \tprivate void initSession() throws TransportException {\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/util/QuotedString.java b/org.spearce.jgit/src/org/spearce/jgit/util/QuotedString.java\nindex 1089e9e..d2f71b4 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/util/QuotedString.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/util/QuotedString.java\n@@ -57,6 +57,9 @@\n \t */\n \tpublic static final BourneStyle BOURNE = new BourneStyle();\n \n+\t/** Bourne style, but permits <code>~user</code> at the start of the string. */\n+\tpublic static final BourneUserPathStyle BOURNE_USER_PATH = new BourneUserPathStyle();\n+\n \t/**\n \t * Quote an input string by the quoting rules.\n \t * <p>\n@@ -176,6 +179,31 @@ public String dequote(final byte[] in, int ip, final int ie) {\n \t\t}\n \t}\n \n+\t/** Bourne style, but permits <code>~user</code> at the start of the string. */\n+\tpublic static class BourneUserPathStyle extends BourneStyle {\n+\t\t@Override\n+\t\tpublic String quote(final String in) {\n+\t\t\tif (in.matches(\"^~[A-Za-z0-9_-]+$\")) {\n+\t\t\t\t// If the string is just \"~user\" we can assume they\n+\t\t\t\t// mean \"~user/\".\n+\t\t\t\t//\n+\t\t\t\treturn in + \"/\";\n+\t\t\t}\n+\n+\t\t\tif (in.matches(\"^~[A-Za-z0-9_-]*/.*$\")) {\n+\t\t\t\t// If the string is of \"~/path\" or \"~user/path\"\n+\t\t\t\t// we must not escape ~/ or ~user/ from the shell.\n+\t\t\t\t//\n+\t\t\t\tfinal int i = in.indexOf('/') + 1;\n+\t\t\t\tif (i == in.length())\n+\t\t\t\t\treturn in;\n+\t\t\t\treturn in.substring(0, i) + super.quote(in.substring(i));\n+\t\t\t}\n+\n+\t\t\treturn super.quote(in);\n+\t\t}\n+\t}\n+\n \t/** Quoting style that obeys the rules of the C programming language. */\n \tpublic static final class C_Style extends QuotedString {\n \t\tprivate static final byte[] quote;\n-- \n1.6.1.rc2.299.gead4c\n"},{"id":"97539","messageId":"200812110022.03719.robin.rosenberg@dewire.com","threadId":"16674","inReplyTo":"1228946751-12708-5-git-send-email-spearce@spearce.org","subject":"Re: [JGIT PATCH 4/6] Add QuotedString class to handle C-style quoting rules","fromName":"Robin Rosenberg","fromEmail":"robin.rosenberg@dewire.com","sentAt":"2008-12-10T23:22:03Z","receivedAt":"2008-12-10T23:22:03Z","isPatch":true,"sender":{"key":"robin.rosenberg@dewire.com","avatar":"https://avatars.githubusercontent.com/u/46357?v=4"},"body":"onsdag 10 december 2008 23:05:49 skrev Shawn O. Pearce:\n> Git patch files can contain file names which are quoted using the\n> C language quoting rules.  In order to correctly create or parse\n\nShould we maybe call this Git-style since we really do not care\nabout C (which version btw?).\n\n> QuotedString itself is an abstract API so callers can be passed a\n> quoting style based on the context of where their output will be\n> used, and multiple styles could be supported.  This may be useful\n> if jgit ever grows a \"git for-each-ref\" style of output where Perl,\n> Python, Tcl and Bourne style quoting might be necessary.\n> \n> References through the singleton QuotedString.C should be able to\n> bypass the virtual function table, as the specific type is mentioned\n> in the field declaration and that type is final.  A good JIT should\n> be able to remove the abstraction costs when the caller has hardcoded\n> the quoting style.\nMaking two interfaces is better. We may share the implementation initially,\nbut parsing file names in Git patches and parsing C strings are different\noperations.\n\n> +\tpublic void testQuote_OctalAll() {\n> +\t\tassertQuote(\"\\1\", \"\\\\001\");\n> +\t\tassertQuote(\"~\", \"\\\\176\");\n> +\t\tassertQuote(\"\\u00ff\", \"\\\\303\\\\277\"); // \\u00ff in UTF-8\n> +\t}\nWhat do we do with non-UTF8 names? I think we should\nfollow the logic we use when parsing commits and paths\nin other places.\n> +\n> +\tpublic void testDequote_UnknownEscapeQ() {\n> +\t\tassertDequote(\"\\\\q\", \"\\\\q\");\n> +\t}\nWould Git generate this style in a name? \n\n> +\t\t\tquote[' '] = 0;\n> +\t\t\tquote['+'] = 0;\n> +\t\t\tquote[','] = 0;\n> +\t\t\tquote['-'] = 0;\n> +\t\t\tquote['.'] = 0;\n> +\t\t\tquote['/'] = 0;\n> +\t\t\tquote['='] = 0;\n> +\t\t\tquote['_'] = 0;\n> +\t\t\tquote['^'] = 0;\n> +\n> +\t\t\tquote['\\u0007'] = 'a';\n> +\t\t\tquote['\\b'] = 'b';\n\\e = esc\n\n> +\t\t\t\tdefault:\n> +\t\t\t\t\t// Any other code is taken literally.\n> +\t\t\t\t\t//\n> +\t\t\t\t\tr[rPtr++] = '\\\\';\n> +\t\t\t\t\tr[rPtr++] = in[inPtr - 1];\n> +\t\t\t\t\tcontinue;\n> +\t\t\t\t}\n> +\t\t\t}\n> +\n> +\t\t\treturn decode(Constants.CHARSET, r, 0, rPtr);\n\nImporting methods really obscures things. Please qualify with class name\nof RawparseUtils here instead. \n\n-- robin\n"},{"id":"97543","messageId":"20081210234130.GB32487@spearce.org","threadId":"16674","inReplyTo":"200812110022.03719.robin.rosenberg@dewire.com","subject":"Re: [JGIT PATCH 4/6] Add QuotedString class to handle C-style quoting rules","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2008-12-10T23:41:30Z","receivedAt":"2008-12-10T23:41:30Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Robin Rosenberg <robin.rosenberg@dewire.com> wrote:\n> onsdag 10 december 2008 23:05:49 skrev Shawn O. Pearce:\n> > Git patch files can contain file names which are quoted using the\n> > C language quoting rules.  In order to correctly create or parse\n> \n> Should we maybe call this Git-style since we really do not care\n> about C (which version btw?).\n\nYea, I think you are right.  I'll change the name.\n \n> Making two interfaces is better. We may share the implementation initially,\n> but parsing file names in Git patches and parsing C strings are different\n> operations.\n\nWell, if we ever supported other C-style string names we could just\nswap the implementation reference.  I'll try to make it clearer\nthis format, although like a C-style string, is really meant for\nGit path names within patches.\n \n> > +\tpublic void testQuote_OctalAll() {\n> > +\t\tassertQuote(\"\\1\", \"\\\\001\");\n> > +\t\tassertQuote(\"~\", \"\\\\176\");\n> > +\t\tassertQuote(\"\\u00ff\", \"\\\\303\\\\277\"); // \\u00ff in UTF-8\n> > +\t}\n>\n> What do we do with non-UTF8 names? I think we should\n> follow the logic we use when parsing commits and paths\n> in other places.\n\nThen we're totally f'd.\n\nGit has no specific encoding on file names.  If we get a standard\nJava Unicode string and get asked to quote it characters with\ncode points above 127 need to be escaped as an octal escape code\naccording to the Git style.  Further the Git style only permits\noctal escapes that result in a value <= 255, aka an unsigned char.\n\nThe name needs to be encoded into an 8-bit encoding, and UTF-8 is\nthe only encoding that will represent every valid Unicode character.\nElsewhere we sort of take the attitude that when writing data *out*\nwe produce UTF-8, even if we read in ISO-whatever.  Here I'm doing\nthe same thing.\n\n> > +\tpublic void testDequote_UnknownEscapeQ() {\n> > +\t\tassertDequote(\"\\\\q\", \"\\\\q\");\n> > +\t}\n>\n> Would Git generate this style in a name? \n\nNo, but a mangled patch might have it.  Rather than throw an\nexception I try to parse the string as faithfully as I can, so we\ncan continue on and mine the stream for more information.  We may\nbe able to work around the breakage (there's a lot of redundant\ndata about path names in the git patch format).\n\nAs far as I can tell C Git handles this style of escape the same way:\n\n  $ cat F\n  diff --git \"a/\\q\" \"b/\\q\"\n  --- \"a/\\q\"\n  +++ \"b/\\q\"\n  $ git apply --stat F\n   \"\\\\q\\\"\" |    0\n   1 files changed, 0 insertions(+), 0 deletions(-)\n\nActually, I think there's a bug, its reading the closing quote as\npart of the file name.  But anyway, my point is that C git handles\nan unknown escape sequence as though it were a literal.\n \n> > +\t\t\tquote['\\b'] = 'b';\n> \\e = esc\n\nOddly enough, C Git doesn't output \\e.  It uses \\033.  It doesn't\nrecognize \\e either, so we can't produce it even if we wanted to\nhonor it on input.  I can add it to our input table (but keep it\nout of our output table), but then we'd treat \\e as \\033 while C\nGit would treat \\e as a literal.  Bad.\n\nSo no, I won't add \\e here.\n\n> > +\t\t\treturn decode(Constants.CHARSET, r, 0, rPtr);\n> \n> Importing methods really obscures things. Please qualify with class name\n> of RawparseUtils here instead. \n\nHmmph.  I wonder how you'll feel then about the patch parser code.\nI import 4 methods from RawParseUtils because they are so commonly\ninvoked that I got tired of reading RawParseUtils.foo.\n\nThere's only two calls here so I changed it to be qualified.\n\n-- \nShawn.\n"},{"id":"97553","messageId":"200812110133.51614.robin.rosenberg@dewire.com","threadId":"16674","inReplyTo":"20081210234130.GB32487@spearce.org","subject":"Re: [JGIT PATCH 4/6] Add QuotedString class to handle C-style quoting rules","fromName":"Robin Rosenberg","fromEmail":"robin.rosenberg@dewire.com","sentAt":"2008-12-11T00:33:51Z","receivedAt":"2008-12-11T00:33:51Z","isPatch":true,"sender":{"key":"robin.rosenberg@dewire.com","avatar":"https://avatars.githubusercontent.com/u/46357?v=4"},"body":"torsdag 11 december 2008 00:41:30 skrev Shawn O. Pearce:\n> > > +\tpublic void testQuote_OctalAll() {\n> > > +\t\tassertQuote(\"\\1\", \"\\\\001\");\n> > > +\t\tassertQuote(\"~\", \"\\\\176\");\n> > > +\t\tassertQuote(\"\\u00ff\", \"\\\\303\\\\277\"); // \\u00ff in UTF-8\n> > > +\t}\n> >\n> > What do we do with non-UTF8 names? I think we should\n> > follow the logic we use when parsing commits and paths\n> > in other places.\n> \n> Then we're totally f'd.\n> \n> Git has no specific encoding on file names.  If we get a standard\n> Java Unicode string and get asked to quote it characters with\n> code points above 127 need to be escaped as an octal escape code\n> according to the Git style.  Further the Git style only permits\n> octal escapes that result in a value <= 255, aka an unsigned char.\n> \n> The name needs to be encoded into an 8-bit encoding, and UTF-8 is\n> the only encoding that will represent every valid Unicode character.\n> Elsewhere we sort of take the attitude that when writing data *out*\n> we produce UTF-8, even if we read in ISO-whatever.  Here I'm doing\n> the same thing.\n\nSo this should pass, right?\n\n\tpublic void testDeQuote_Latin1() {\n\t\tassertDequote(\"\\u00c5ngstr\\u00f6m\", \"\\\\305ngstr\\\\366m\"); // Latin1\n\t}\n\n\tpublic void testDeQuote_UTF8() {\n\t\tassertDequote(\"\\u00c5ngstr\\u00f6m\", \"\\\\303\\\\205ngstr\\\\303\\\\266m\");\n\t}\n\nAnd possibly these actuall unquoted names, which can be produced when\ncore.quotepath is false\n\n\tpublic void testDeQuote_Rawlatin() {\n\t\tassertDequote(\"\\u00c5ngstr\\u00f6m\", \"\\305ngstr\\366m\");\n\t}\n\n\tpublic void testDeQuote_RawUTF8() {\n\t\tassertDequote(\"\\u00c5ngstr\\u00f6m\", \"\\303\\205ngstr\\303\\266m\");\n\t}\n\nYou also reversed the arguments to testQuote. It think we should follow the\n\"expected\"-first conventions here too. The case above works neither way.\nUsing Constant.encode in the test is kind of dangerous as it does too\nmany conversions, so you don't know what you're testing anymore. Changing\nassertDequote like this makes us able to feed byte sequences as strings\nto the test method (which we cannot do if we assume UTF-8 encoding). ISO-\nlatin-encoding allows any byte sequence to be entered conveniently.\n\n\tprivate static void assertDequote(final String exp, final String in) {\n\t\tfinal byte[] b;\n\t\ttry {\n\t\t\tb = ('\"' + in + '\"').getBytes(\"ISO-8859-1\");\n\t\t} catch (UnsupportedEncodingException e) {\n\t\t\tthrow new RuntimeException(e);\n\t\t}\n\t\tfinal String r = C.dequote(b, 0, b.length);\n\t\tassertEquals(exp, r);\n\t}\n\n-- robin\n"},{"id":"97560","messageId":"20081211005742.GC32487@spearce.org","threadId":"16674","inReplyTo":"200812110133.51614.robin.rosenberg@dewire.com","subject":"[JGIT PATCH 4/6 v3] Add QuotedString class to handle Git path style quoting rules","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2008-12-11T00:57:42Z","receivedAt":"2008-12-11T00:57:42Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Git patch files can contain file names which are quoted using the\nroughly the C language quoting rules.  In order to correctly create\nor parse these files we must implement a quoting style that matches\nthose specific rules.\n\nQuotedString itself is an abstract API so callers can be passed a\nquoting style based on the context of where their output will be\nused, and multiple styles could be supported.  This may be useful\nif jgit ever grows a \"git for-each-ref\" style of output where Perl,\nPython, Tcl and Bourne style quoting might be necessary.\n\nReferences through the singleton QuotedString.GIT_PATH should be\nable to bypass the virtual function table, as the specific type is\nmentioned in the field declaration and that type is final.  A good\nJIT should be able to remove the abstraction costs when the caller\nhas hardcoded the quoting style.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n  Robin Rosenberg <robin.rosenberg@dewire.com> wrote:\n  > So this should pass, right?\n\n  These tests have been added, and they pass.\n\n  > You also reversed the arguments to testQuote. It think we should follow the\n  > \"expected\"-first conventions here too.\n\n  Fixed.\n\n  > Using Constant.encode in the test is kind of dangerous as it does too\n  > many conversions,\n\n  Fixed.\n\n .../jgit/util/QuotedStringGitPathStyleTest.java    |  172 +++++++++++++\n .../src/org/spearce/jgit/util/QuotedString.java    |  268 ++++++++++++++++++++\n 2 files changed, 440 insertions(+), 0 deletions(-)\n create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/util/QuotedStringGitPathStyleTest.java\n create mode 100644 org.spearce.jgit/src/org/spearce/jgit/util/QuotedString.java\n\ndiff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/util/QuotedStringGitPathStyleTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/util/QuotedStringGitPathStyleTest.java\nnew file mode 100644\nindex 0000000..54fbd31\n--- /dev/null\n+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/util/QuotedStringGitPathStyleTest.java\n@@ -0,0 +1,172 @@\n+/*\n+ * Copyright (C) 2008, Google Inc.\n+ *\n+ * All rights reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or\n+ * without modification, are permitted provided that the following\n+ * conditions are met:\n+ *\n+ * - Redistributions of source code must retain the above copyright\n+ *   notice, this list of conditions and the following disclaimer.\n+ *\n+ * - Redistributions in binary form must reproduce the above\n+ *   copyright notice, this list of conditions and the following\n+ *   disclaimer in the documentation and/or other materials provided\n+ *   with the distribution.\n+ *\n+ * - Neither the name of the Git Development Community nor the\n+ *   names of its contributors may be used to endorse or promote\n+ *   products derived from this software without specific prior\n+ *   written permission.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND\n+ * CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES,\n+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\n+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\n+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\n+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+\n+package org.spearce.jgit.util;\n+\n+import static org.spearce.jgit.util.QuotedString.GIT_PATH;\n+\n+import java.io.UnsupportedEncodingException;\n+\n+import junit.framework.TestCase;\n+\n+import org.spearce.jgit.lib.Constants;\n+\n+public class QuotedStringGitPathStyleTest extends TestCase {\n+\tprivate static void assertQuote(final String exp, final String in) {\n+\t\tfinal String r = GIT_PATH.quote(in);\n+\t\tassertNotSame(in, r);\n+\t\tassertFalse(in.equals(r));\n+\t\tassertEquals('\"' + exp + '\"', r);\n+\t}\n+\n+\tprivate static void assertDequote(final String exp, final String in) {\n+\t\tfinal byte[] b;\n+\t\ttry {\n+\t\t\tb = ('\"' + in + '\"').getBytes(\"ISO-8859-1\");\n+\t\t} catch (UnsupportedEncodingException e) {\n+\t\t\tthrow new RuntimeException(e);\n+\t\t}\n+\t\tfinal String r = GIT_PATH.dequote(b, 0, b.length);\n+\t\tassertEquals(exp, r);\n+\t}\n+\n+\tpublic void testQuote_Empty() {\n+\t\tassertEquals(\"\\\"\\\"\", GIT_PATH.quote(\"\"));\n+\t}\n+\n+\tpublic void testDequote_Empty1() {\n+\t\tassertEquals(\"\", GIT_PATH.dequote(new byte[0], 0, 0));\n+\t}\n+\n+\tpublic void testDequote_Empty2() {\n+\t\tassertEquals(\"\", GIT_PATH.dequote(new byte[] { '\"', '\"' }, 0, 2));\n+\t}\n+\n+\tpublic void testDequote_SoleDq() {\n+\t\tassertEquals(\"\\\"\", GIT_PATH.dequote(new byte[] { '\"' }, 0, 1));\n+\t}\n+\n+\tpublic void testQuote_BareA() {\n+\t\tfinal String in = \"a\";\n+\t\tassertSame(in, GIT_PATH.quote(in));\n+\t}\n+\n+\tpublic void testDequote_BareA() {\n+\t\tfinal String in = \"a\";\n+\t\tfinal byte[] b = Constants.encode(in);\n+\t\tassertEquals(in, GIT_PATH.dequote(b, 0, b.length));\n+\t}\n+\n+\tpublic void testDequote_BareABCZ_OnlyBC() {\n+\t\tfinal String in = \"abcz\";\n+\t\tfinal byte[] b = Constants.encode(in);\n+\t\tfinal int p = in.indexOf('b');\n+\t\tassertEquals(\"bc\", GIT_PATH.dequote(b, p, p + 2));\n+\t}\n+\n+\tpublic void testDequote_LoneBackslash() {\n+\t\tassertDequote(\"\\\\\", \"\\\\\");\n+\t}\n+\n+\tpublic void testQuote_NamedEscapes() {\n+\t\tassertQuote(\"\\\\a\", \"\\u0007\");\n+\t\tassertQuote(\"\\\\b\", \"\\b\");\n+\t\tassertQuote(\"\\\\f\", \"\\f\");\n+\t\tassertQuote(\"\\\\n\", \"\\n\");\n+\t\tassertQuote(\"\\\\r\", \"\\r\");\n+\t\tassertQuote(\"\\\\t\", \"\\t\");\n+\t\tassertQuote(\"\\\\v\", \"\\u000B\");\n+\t\tassertQuote(\"\\\\\\\\\", \"\\\\\");\n+\t\tassertQuote(\"\\\\\\\"\", \"\\\"\");\n+\t}\n+\n+\tpublic void testDequote_NamedEscapes() {\n+\t\tassertDequote(\"\\u0007\", \"\\\\a\");\n+\t\tassertDequote(\"\\b\", \"\\\\b\");\n+\t\tassertDequote(\"\\f\", \"\\\\f\");\n+\t\tassertDequote(\"\\n\", \"\\\\n\");\n+\t\tassertDequote(\"\\r\", \"\\\\r\");\n+\t\tassertDequote(\"\\t\", \"\\\\t\");\n+\t\tassertDequote(\"\\u000B\", \"\\\\v\");\n+\t\tassertDequote(\"\\\\\", \"\\\\\\\\\");\n+\t\tassertDequote(\"\\\"\", \"\\\\\\\"\");\n+\t}\n+\n+\tpublic void testDequote_OctalAll() {\n+\t\tfor (int i = 0; i < 256; i++) {\n+\t\t\tString s = Integer.toOctalString(i);\n+\t\t\twhile (s.length() < 3) {\n+\t\t\t\ts = \"0\" + s;\n+\t\t\t}\n+\t\t\tassertDequote(\"\" + (char) i, \"\\\\\" + s);\n+\t\t}\n+\t}\n+\n+\tpublic void testQuote_OctalAll() {\n+\t\tassertQuote(\"\\\\001\", \"\\1\");\n+\t\tassertQuote(\"\\\\176\", \"~\");\n+\t\tassertQuote(\"\\\\303\\\\277\", \"\\u00ff\"); // \\u00ff in UTF-8\n+\t}\n+\n+\tpublic void testDequote_UnknownEscapeQ() {\n+\t\tassertDequote(\"\\\\q\", \"\\\\q\");\n+\t}\n+\n+\tpublic void testDequote_FooTabBar() {\n+\t\tassertDequote(\"foo\\tbar\", \"foo\\\\tbar\");\n+\t}\n+\n+\tpublic void testDequote_Latin1() {\n+\t\tassertDequote(\"\\u00c5ngstr\\u00f6m\", \"\\\\305ngstr\\\\366m\"); // Latin1\n+\t}\n+\n+\tpublic void testDequote_UTF8() {\n+\t\tassertDequote(\"\\u00c5ngstr\\u00f6m\", \"\\\\303\\\\205ngstr\\\\303\\\\266m\");\n+\t}\n+\n+\tpublic void testDequote_RawUTF8() {\n+\t\tassertDequote(\"\\u00c5ngstr\\u00f6m\", \"\\303\\205ngstr\\303\\266m\");\n+\t}\n+\n+\tpublic void testDequote_RawLatin1() {\n+\t\tassertDequote(\"\\u00c5ngstr\\u00f6m\", \"\\305ngstr\\366m\");\n+\t}\n+\n+\tpublic void testQuote_Ang() {\n+\t\tassertQuote(\"\\\\303\\\\205ngstr\\\\303\\\\266m\", \"\\u00c5ngstr\\u00f6m\");\n+\t}\n+}\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/util/QuotedString.java b/org.spearce.jgit/src/org/spearce/jgit/util/QuotedString.java\nnew file mode 100644\nindex 0000000..279b713\n--- /dev/null\n+++ b/org.spearce.jgit/src/org/spearce/jgit/util/QuotedString.java\n@@ -0,0 +1,268 @@\n+/*\n+ * Copyright (C) 2008, Google Inc.\n+ *\n+ * All rights reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or\n+ * without modification, are permitted provided that the following\n+ * conditions are met:\n+ *\n+ * - Redistributions of source code must retain the above copyright\n+ *   notice, this list of conditions and the following disclaimer.\n+ *\n+ * - Redistributions in binary form must reproduce the above\n+ *   copyright notice, this list of conditions and the following\n+ *   disclaimer in the documentation and/or other materials provided\n+ *   with the distribution.\n+ *\n+ * - Neither the name of the Git Development Community nor the\n+ *   names of its contributors may be used to endorse or promote\n+ *   products derived from this software without specific prior\n+ *   written permission.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND\n+ * CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES,\n+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\n+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\n+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\n+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+\n+package org.spearce.jgit.util;\n+\n+import java.util.Arrays;\n+\n+import org.spearce.jgit.lib.Constants;\n+\n+/** Utility functions related to quoted string handling. */\n+public abstract class QuotedString {\n+\t/** Quoting style that obeys the rules Git applies to file names */\n+\tpublic static final GitPathStyle GIT_PATH = new GitPathStyle();\n+\n+\t/**\n+\t * Quote an input string by the quoting rules.\n+\t * <p>\n+\t * If the input string does not require any quoting, the same String\n+\t * reference is returned to the caller.\n+\t * <p>\n+\t * Otherwise a quoted string is returned, including the opening and closing\n+\t * quotation marks at the start and end of the string. If the style does not\n+\t * permit raw Unicode characters then the string will first be encoded in\n+\t * UTF-8, with unprintable sequences possibly escaped by the rules.\n+\t * \n+\t * @param in\n+\t *            any non-null Unicode string.\n+\t * @return a quoted string. See above for details.\n+\t */\n+\tpublic abstract String quote(String in);\n+\n+\t/**\n+\t * Clean a previously quoted input, decoding the result via UTF-8.\n+\t * <p>\n+\t * This method must match quote such that:\n+\t * \n+\t * <pre>\n+\t * a.equals(dequote(quote(a)));\n+\t * </pre>\n+\t * \n+\t * is true for any <code>a</code>.\n+\t * \n+\t * @param in\n+\t *            a Unicode string to remove quoting from.\n+\t * @return the cleaned string.\n+\t * @see #dequote(byte[], int, int)\n+\t */\n+\tpublic String dequote(final String in) {\n+\t\tfinal byte[] b = Constants.encode(in);\n+\t\treturn dequote(b, 0, b.length);\n+\t}\n+\n+\t/**\n+\t * Decode a previously quoted input, scanning a UTF-8 encoded buffer.\n+\t * <p>\n+\t * This method must match quote such that:\n+\t * \n+\t * <pre>\n+\t * a.equals(dequote(Constants.encode(quote(a))));\n+\t * </pre>\n+\t * \n+\t * is true for any <code>a</code>.\n+\t * <p>\n+\t * This method removes any opening/closing quotation marks added by\n+\t * {@link #quote(String)}.\n+\t * \n+\t * @param in\n+\t *            the input buffer to parse.\n+\t * @param offset\n+\t *            first position within <code>in</code> to scan.\n+\t * @param end\n+\t *            one position past in <code>in</code> to scan.\n+\t * @return the cleaned string.\n+\t */\n+\tpublic abstract String dequote(byte[] in, int offset, int end);\n+\n+\t/** Quoting style that obeys the rules Git applies to file names */\n+\tpublic static final class GitPathStyle extends QuotedString {\n+\t\tprivate static final byte[] quote;\n+\t\tstatic {\n+\t\t\tquote = new byte[128];\n+\t\t\tArrays.fill(quote, (byte) -1);\n+\n+\t\t\tfor (int i = '0'; i <= '9'; i++)\n+\t\t\t\tquote[i] = 0;\n+\t\t\tfor (int i = 'a'; i <= 'z'; i++)\n+\t\t\t\tquote[i] = 0;\n+\t\t\tfor (int i = 'A'; i <= 'Z'; i++)\n+\t\t\t\tquote[i] = 0;\n+\t\t\tquote[' '] = 0;\n+\t\t\tquote['+'] = 0;\n+\t\t\tquote[','] = 0;\n+\t\t\tquote['-'] = 0;\n+\t\t\tquote['.'] = 0;\n+\t\t\tquote['/'] = 0;\n+\t\t\tquote['='] = 0;\n+\t\t\tquote['_'] = 0;\n+\t\t\tquote['^'] = 0;\n+\n+\t\t\tquote['\\u0007'] = 'a';\n+\t\t\tquote['\\b'] = 'b';\n+\t\t\tquote['\\f'] = 'f';\n+\t\t\tquote['\\n'] = 'n';\n+\t\t\tquote['\\r'] = 'r';\n+\t\t\tquote['\\t'] = 't';\n+\t\t\tquote['\\u000B'] = 'v';\n+\t\t\tquote['\\\\'] = '\\\\';\n+\t\t\tquote['\"'] = '\"';\n+\t\t}\n+\n+\t\t@Override\n+\t\tpublic String quote(final String instr) {\n+\t\t\tif (instr.length() == 0)\n+\t\t\t\treturn \"\\\"\\\"\";\n+\t\t\tboolean reuse = true;\n+\t\t\tfinal byte[] in = Constants.encode(instr);\n+\t\t\tfinal StringBuilder r = new StringBuilder(2 + in.length);\n+\t\t\tr.append('\"');\n+\t\t\tfor (int i = 0; i < in.length; i++) {\n+\t\t\t\tfinal int c = in[i] & 0xff;\n+\t\t\t\tif (c < quote.length) {\n+\t\t\t\t\tfinal byte style = quote[c];\n+\t\t\t\t\tif (style == 0) {\n+\t\t\t\t\t\tr.append((char) c);\n+\t\t\t\t\t\tcontinue;\n+\t\t\t\t\t}\n+\t\t\t\t\tif (style > 0) {\n+\t\t\t\t\t\treuse = false;\n+\t\t\t\t\t\tr.append('\\\\');\n+\t\t\t\t\t\tr.append((char) style);\n+\t\t\t\t\t\tcontinue;\n+\t\t\t\t\t}\n+\t\t\t\t}\n+\n+\t\t\t\treuse = false;\n+\t\t\t\tr.append('\\\\');\n+\t\t\t\tr.append((char) (((c >> 6) & 03) + '0'));\n+\t\t\t\tr.append((char) (((c >> 3) & 07) + '0'));\n+\t\t\t\tr.append((char) (((c >> 0) & 07) + '0'));\n+\t\t\t}\n+\t\t\tif (reuse)\n+\t\t\t\treturn instr;\n+\t\t\tr.append('\"');\n+\t\t\treturn r.toString();\n+\t\t}\n+\n+\t\t@Override\n+\t\tpublic String dequote(final byte[] in, final int inPtr, final int inEnd) {\n+\t\t\tif (2 <= inEnd - inPtr && in[inPtr] == '\"' && in[inEnd - 1] == '\"')\n+\t\t\t\treturn dq(in, inPtr + 1, inEnd - 1);\n+\t\t\treturn RawParseUtils.decode(Constants.CHARSET, in, inPtr, inEnd);\n+\t\t}\n+\n+\t\tprivate static String dq(final byte[] in, int inPtr, final int inEnd) {\n+\t\t\tfinal byte[] r = new byte[inEnd - inPtr];\n+\t\t\tint rPtr = 0;\n+\t\t\twhile (inPtr < inEnd) {\n+\t\t\t\tfinal byte b = in[inPtr++];\n+\t\t\t\tif (b != '\\\\') {\n+\t\t\t\t\tr[rPtr++] = b;\n+\t\t\t\t\tcontinue;\n+\t\t\t\t}\n+\n+\t\t\t\tif (inPtr == inEnd) {\n+\t\t\t\t\t// Lone trailing backslash. Treat it as a literal.\n+\t\t\t\t\t//\n+\t\t\t\t\tr[rPtr++] = '\\\\';\n+\t\t\t\t\tbreak;\n+\t\t\t\t}\n+\n+\t\t\t\tswitch (in[inPtr++]) {\n+\t\t\t\tcase 'a':\n+\t\t\t\t\tr[rPtr++] = 0x07 /* \\a = BEL */;\n+\t\t\t\t\tcontinue;\n+\t\t\t\tcase 'b':\n+\t\t\t\t\tr[rPtr++] = '\\b';\n+\t\t\t\t\tcontinue;\n+\t\t\t\tcase 'f':\n+\t\t\t\t\tr[rPtr++] = '\\f';\n+\t\t\t\t\tcontinue;\n+\t\t\t\tcase 'n':\n+\t\t\t\t\tr[rPtr++] = '\\n';\n+\t\t\t\t\tcontinue;\n+\t\t\t\tcase 'r':\n+\t\t\t\t\tr[rPtr++] = '\\r';\n+\t\t\t\t\tcontinue;\n+\t\t\t\tcase 't':\n+\t\t\t\t\tr[rPtr++] = '\\t';\n+\t\t\t\t\tcontinue;\n+\t\t\t\tcase 'v':\n+\t\t\t\t\tr[rPtr++] = 0x0B/* \\v = VT */;\n+\t\t\t\t\tcontinue;\n+\n+\t\t\t\tcase '\\\\':\n+\t\t\t\tcase '\"':\n+\t\t\t\t\tr[rPtr++] = in[inPtr - 1];\n+\t\t\t\t\tcontinue;\n+\n+\t\t\t\tcase '0':\n+\t\t\t\tcase '1':\n+\t\t\t\tcase '2':\n+\t\t\t\tcase '3': {\n+\t\t\t\t\tint cp = in[inPtr - 1] - '0';\n+\t\t\t\t\twhile (inPtr < inEnd) {\n+\t\t\t\t\t\tfinal byte c = in[inPtr];\n+\t\t\t\t\t\tif ('0' <= c && c <= '7') {\n+\t\t\t\t\t\t\tcp <<= 3;\n+\t\t\t\t\t\t\tcp |= c - '0';\n+\t\t\t\t\t\t\tinPtr++;\n+\t\t\t\t\t\t} else {\n+\t\t\t\t\t\t\tbreak;\n+\t\t\t\t\t\t}\n+\t\t\t\t\t}\n+\t\t\t\t\tr[rPtr++] = (byte) cp;\n+\t\t\t\t\tcontinue;\n+\t\t\t\t}\n+\n+\t\t\t\tdefault:\n+\t\t\t\t\t// Any other code is taken literally.\n+\t\t\t\t\t//\n+\t\t\t\t\tr[rPtr++] = '\\\\';\n+\t\t\t\t\tr[rPtr++] = in[inPtr - 1];\n+\t\t\t\t\tcontinue;\n+\t\t\t\t}\n+\t\t\t}\n+\n+\t\t\treturn RawParseUtils.decode(Constants.CHARSET, r, 0, rPtr);\n+\t\t}\n+\n+\t\tprivate GitPathStyle() {\n+\t\t\t// Singleton\n+\t\t}\n+\t}\n+}\n-- \n1.6.1.rc2.299.gead4c\n\n\n-- \nShawn.\n"}]}