Tarantool development patches archive
 help / color / mirror / Atom feed
* [tarantool-patches] [PATCH v1 1/1] third_party: fix strings "true"/"false" in yaml
@ 2018-07-12 12:58 Kirill Shcherbatov
  2018-07-13  6:48 ` [tarantool-patches] " Kirill Yukhin
  2018-07-19 10:54 ` Kirill Yukhin
  0 siblings, 2 replies; 4+ messages in thread
From: Kirill Shcherbatov @ 2018-07-12 12:58 UTC (permalink / raw)
  To: tarantool-patches; +Cc: v.shpilevoy, Kirill Shcherbatov

Strings containing "true" and "false" were converted
to a boolean type when serializing. Fixed.
Example:
type(yaml.decode(yaml.encode('false'))) == string
type(yaml.decode(yaml.encode('true'))) == string

Closes #3476.
---
https://github.com/tarantool/tarantool/compare/kshch/gh-3476-yaml-strings-with-true-and-false
https://github.com/tarantool/tarantool/issues/3476

 test/app-tap/console.test.lua | 10 +++++++++-
 third_party/lua-yaml/lyaml.cc |  7 +++++--
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/test/app-tap/console.test.lua b/test/app-tap/console.test.lua
index f055958..1c76072 100755
--- a/test/app-tap/console.test.lua
+++ b/test/app-tap/console.test.lua
@@ -21,7 +21,7 @@ local EOL = "\n...\n"
 
 test = tap.test("console")
 
-test:plan(53)
+test:plan(57)
 
 -- Start console and connect to it
 local server = console.listen(CONSOLE_SOCKET)
@@ -67,6 +67,14 @@ test:is(yaml.decode(client:read(EOL))[1], ';', "get delimiter is ';'")
 client:write("require('console').delimiter('');\n")
 test:is(yaml.decode(client:read(EOL)), '', "clear delimiter")
 
+--
+-- gh-3476: yaml.encode encodes 'false' and 'true' incorrectly.
+--
+test:is(type(yaml.decode(yaml.encode('false'))), 'string')
+test:is(type(yaml.decode(yaml.encode('true'))), 'string')
+test:is(type(yaml.decode(yaml.encode({a = 'false'})).a), 'string')
+test:is(type(yaml.decode(yaml.encode({a = 'false'})).a), 'string')
+
 box.cfg{
     listen=IPROTO_SOCKET;
     memtx_memory = 107374182,
diff --git a/third_party/lua-yaml/lyaml.cc b/third_party/lua-yaml/lyaml.cc
index 14eabca..c6d118a 100644
--- a/third_party/lua-yaml/lyaml.cc
+++ b/third_party/lua-yaml/lyaml.cc
@@ -605,9 +605,12 @@ static int dump_node(struct lua_yaml_dumper *dumper)
       if (utf8_check_printable(str, len)) {
          if (yaml_is_flow_mode(dumper)) {
             style = YAML_SINGLE_QUOTED_SCALAR_STYLE;
-         } else if (strstr(str, "\n\n") != NULL) {
+         } else if (strstr(str, "\n\n") != NULL || strcmp(str, "true") == 0 ||
+		    strcmp(str, "false") == 0) {
             /*
-             * Tarantool-specific: use literal style for string with empty lines.
+             * Tarantool-specific: use literal style for string
+             * with empty lines and strings representing boolean
+             * types.
              * Useful for tutorial().
              */
             style = YAML_LITERAL_SCALAR_STYLE;
-- 
2.7.4

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-07-19 12:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-12 12:58 [tarantool-patches] [PATCH v1 1/1] third_party: fix strings "true"/"false" in yaml Kirill Shcherbatov
2018-07-13  6:48 ` [tarantool-patches] " Kirill Yukhin
2018-07-19 10:54 ` Kirill Yukhin
2018-07-19 12:11   ` Alexander Turenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox