Merge pull request #4 from tillberg/fix-prefix-repeat
Fix prefix-repeat bug in Join when arguments include special characters and no whitespace
diff --git a/quote.go b/quote.go
index f6cacee..9842d5e 100644
--- a/quote.go
+++ b/quote.go
@@ -50,7 +50,7 @@
if strings.ContainsRune(specialChars, c) || (atStart && strings.ContainsRune(prefixChars, c)) {
// copy the non-special chars up to this point
if len(cur) < len(prev) {
- buf.WriteString(word[0 : len(prev)-len(cur)-l])
+ buf.WriteString(prev[0 : len(prev)-len(cur)-l])
}
buf.WriteByte('\\')
buf.WriteRune(c)
diff --git a/quote_test.go b/quote_test.go
index a4d2d82..0368870 100644
--- a/quote_test.go
+++ b/quote_test.go
@@ -25,4 +25,6 @@
{[]string{"~user", "u~ser", " ~user", "!~user"}, "\\~user u~ser ' ~user' \\!~user"},
{[]string{"foo*", "M{ovies,usic}", "ab[cd]", "%3"}, "foo\\* M\\{ovies,usic} ab\\[cd] %3"},
{[]string{"one", "", "three"}, "one '' three"},
+ {[]string{"some(parentheses)"}, "some\\(parentheses\\)"},
+ {[]string{"$some_ot~her_)spe!cial_*_characters"}, "\\$some_ot~her_\\)spe\\!cial_\\*_characters"},
}