Skip to content

Commit 10a32b2

Browse files
authored
Merge pull request #40 from ijackson/write
2 parents 09a4136 + 62a3aa9 commit 10a32b2

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

lib/TOML/Tiny/Writer.pm

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -197,18 +197,10 @@ sub to_toml_key {
197197

198198
if ($str =~ /^$BareKey$/) {
199199
return $str;
200-
}
201-
202-
# Escape control characters
203-
$str =~ s/([\p{General_Category=Control}])/'\\u00' . unpack('H2', $1)/eg;
204-
205-
# Escape unicode characters
206-
#$str =~ s/($NonASCII)/'\\u00' . unpack('H2', $1)/eg;
207-
208-
if ($str =~ /^"/) {
209-
return qq{'$str'};
210200
} else {
211-
return qq{"$str"};
201+
# Not valid as a "bare key". Encode it as a "quoted key"
202+
# (in TOML terminology), using the "literal string" format.
203+
return to_toml_string($str);
212204
}
213205
}
214206

t/writer.t

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,15 @@ hosts = [
144144
"omega"
145145
]
146146
147+
[cfg."something with a 'single-quote'".nested]
148+
inner = "forty-one"
149+
150+
[cfg.'something with a "double-quote"'.nested]
151+
inner = "forty-two"
152+
153+
[cfg."something with a 'single-quote' and a \"double-quote\"".nested]
154+
inner = "forty-three"
155+
147156
[[products]]
148157
name = "Hammer"
149158
sku = 738594937

0 commit comments

Comments
 (0)