From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id BA68526E40 for ; Thu, 12 Jul 2018 08:59:03 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Q5UGiKum2rjb for ; Thu, 12 Jul 2018 08:59:03 -0400 (EDT) Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 2B9D226C08 for ; Thu, 12 Jul 2018 08:59:03 -0400 (EDT) From: Kirill Shcherbatov Subject: [tarantool-patches] [PATCH v1 1/1] third_party: fix strings "true"/"false" in yaml Date: Thu, 12 Jul 2018 15:58:58 +0300 Message-Id: <0ed926e6936c70a9c7ac7c917f278505c243fe07.1531400260.git.kshcherbatov@tarantool.org> Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-subscribe: List-owner: List-post: List-archive: To: tarantool-patches@freelists.org Cc: v.shpilevoy@tarantool.org, 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