From 87e2e44490aadaa4243afc04b0b35cd4376978ec Mon Sep 17 00:00:00 2001 From: kohsuke Date: Tue, 18 Nov 2008 05:19:55 +0000 Subject: [PATCH] [HUDSON-2584] Fixed a regression introduced in 1.260. Also see http://www.nabble.com/Error-parsing-%22-in-msbuild-task-to20535754.html git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@13297 71c3de6d-444a-0410-be80-ed276b4c234a --- .../java/hudson/util/QuotedStringTokenizer.java | 15 +++++++++++++++ .../hudson/util/QuotedStringTokenizerTest.java | 6 ++++++ 2 files changed, 21 insertions(+) diff --git a/core/src/main/java/hudson/util/QuotedStringTokenizer.java b/core/src/main/java/hudson/util/QuotedStringTokenizer.java index 70a09b4d82..bdc97434a2 100644 --- a/core/src/main/java/hudson/util/QuotedStringTokenizer.java +++ b/core/src/main/java/hudson/util/QuotedStringTokenizer.java @@ -187,6 +187,8 @@ public class QuotedStringTokenizer if (escape) { escape=false; + if(ESCAPABLE_CHARS.indexOf(c)<0) + _token.append('\\'); _token.append(c); } else if(_delim.indexOf(c)>=0) @@ -221,6 +223,8 @@ public class QuotedStringTokenizer if (escape) { escape=false; + if(ESCAPABLE_CHARS.indexOf(c)<0) + _token.append('\\'); _token.append(c); } else if (c=='\'') @@ -245,6 +249,8 @@ public class QuotedStringTokenizer if (escape) { escape=false; + if(ESCAPABLE_CHARS.indexOf(c)<0) + _token.append('\\'); _token.append(c); } else if (c=='\"') @@ -530,6 +536,15 @@ public class QuotedStringTokenizer if ((b >= 'A') && (b <= 'F')) return (byte)(b - 'A' + 10); return 0; } + + /** + * Characters that can be escaped with \. + * + * Others, like, say, \W will be left alone instead of becoming just W. + * This is important to keep Hudson behave on Windows, which uses '\' as + * the directory separator. + */ + private static final String ESCAPABLE_CHARS = "\\\"' "; } diff --git a/core/src/test/java/hudson/util/QuotedStringTokenizerTest.java b/core/src/test/java/hudson/util/QuotedStringTokenizerTest.java index 0786d42d50..7f8c54228f 100644 --- a/core/src/test/java/hudson/util/QuotedStringTokenizerTest.java +++ b/core/src/test/java/hudson/util/QuotedStringTokenizerTest.java @@ -44,4 +44,10 @@ public class QuotedStringTokenizerTest extends TestCase { check("foo\\\\ bar", "foo\\","bar"); } + + // see http://www.nabble.com/Error-parsing-%22-in-msbuild-task-to20535754.html + public void test7() { + check("foo=\"bar\\zot\"", + "foo=bar\\zot"); + } }