chiark / gitweb /
Writer: Fix quoting of table keys
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 2 Aug 2020 16:51:46 +0000 (17:51 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 2 Aug 2020 21:57:41 +0000 (22:57 +0100)
Looking only at the first character to decide how to quote is clearly
a mistake.  And if we end up using " we must do \-escaping.

So replace this broken code.  Instead, we now prefer ' if there is
no ' in the key.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
TOML-Tiny/lib/TOML/Tiny/Writer.pm

index 2d2b79b107811d1a77568a83d7b2bb37718f232b..ddd714f397753446ba6d9d69ffdcf048d4dbcf63 100644 (file)
@@ -168,10 +168,10 @@ sub to_toml_key {
     return $str;
   }
 
-  if ($str =~ /^"/) {
+  if ($str !~ /'/) {
     return qq{'$str'};
   } else {
-    return qq{"$str"};
+    return to_toml_string($str);
   }
 }