quote tabs too
diff --git a/convert.go b/convert.go
index e805e1f..450751d 100644
--- a/convert.go
+++ b/convert.go
@@ -294,12 +294,22 @@
return nil
}
-func quoteIfNeeded(s string) string {
- if strconv.CanBackquote(s) {
- return s
+func isPrint(s string) bool {
+ for _, c := range s {
+ if !strconv.IsPrint(c) {
+ return false
+ }
}
- return strconv.Quote(s)
+ return true
+}
+
+func quoteIfNeeded(s string) string {
+ if !isPrint(s) {
+ return strconv.Quote(s)
+ }
+
+ return s
}
func wrapText(s string, l int, prefix string) string {
diff --git a/help_test.go b/help_test.go
index 6ce55ed..32220fb 100644
--- a/help_test.go
+++ b/help_test.go
@@ -16,7 +16,7 @@
EmptyDescription bool `long:"empty-description"`
Default string `long:"default" default:"Some\nvalue" description:"Test default value"`
- DefaultArray []string `long:"default-array" default:"Some value" default:"Another value" description:"Test default array value"`
+ DefaultArray []string `long:"default-array" default:"Some value" default:"Other\tvalue" description:"Test default array value"`
DefaultMap map[string]string `long:"default-map" default:"some:value" default:"another:value" description:"Testdefault map value"`
EnvDefault1 string `long:"env-default1" default:"Some value" env:"ENV_DEFAULT" description:"Test env-default1 value"`
EnvDefault2 string `long:"env-default2" env:"ENV_DEFAULT" description:"Test env-default2 value"`
@@ -80,7 +80,7 @@
/ptrslice: A slice of pointers to string
/empty-description
/default: Test default value ("Some\nvalue")
- /default-array: Test default array value (Some value, Another value)
+ /default-array: Test default array value (Some value, "Other\tvalue")
/default-map: Testdefault map value (some:value, another:value)
/env-default1: Test env-default1 value (Some value) [%ENV_DEFAULT%]
/env-default2: Test env-default2 value [%ENV_DEFAULT%]
@@ -116,7 +116,7 @@
--ptrslice= A slice of pointers to string
--empty-description
--default= Test default value ("Some\nvalue")
- --default-array= Test default array value (Some value, Another value)
+ --default-array= Test default array value (Some value, "Other\tvalue")
--default-map= Testdefault map value (some:value, another:value)
--env-default1= Test env-default1 value (Some value) [$ENV_DEFAULT]
--env-default2= Test env-default2 value [$ENV_DEFAULT]
diff --git a/ini_private.go b/ini_private.go
index 3a44bd6..c439b80 100644
--- a/ini_private.go
+++ b/ini_private.go
@@ -164,7 +164,7 @@
}
func writeOption(writer io.Writer, optionName string, optionType reflect.Kind, optionKey string, optionValue string, commentOption bool, forceQuote bool) {
- if forceQuote || (optionType == reflect.String && !strconv.CanBackquote(optionValue)) {
+ if forceQuote || (optionType == reflect.String && !isPrint(optionValue)) {
optionValue = strconv.Quote(optionValue)
}
diff --git a/ini_test.go b/ini_test.go
index 47afd37..48b5f2e 100644
--- a/ini_test.go
+++ b/ini_test.go
@@ -59,7 +59,7 @@
; Test default array value
DefaultArray = Some value
-DefaultArray = Another value
+DefaultArray = "Other\tvalue"
; Testdefault map value
DefaultMap = another:value
@@ -114,7 +114,7 @@
; Test default array value
; DefaultArray = Some value
-; DefaultArray = Another value
+; DefaultArray = "Other\tvalue"
; Testdefault map value
; DefaultMap = another:value