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"); + } }