[tarantool-patches] [PATCH v1 1/1] third_party: fix strings "true"/"false" in yaml

Kirill Shcherbatov kshcherbatov at tarantool.org
Thu Jul 12 15:58:58 MSK 2018


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





More information about the Tarantool-patches mailing list