From 8ecba85d4628e4afaeade61a25ed5f1f74069d19 Mon Sep 17 00:00:00 2001
From: Vladimir Davydov <vdavydov@tarantool.org>
Date: Wed, 21 Jun 2023 14:17:47 +0300
Subject: [PATCH] yaml: use standard base64 encoder

Let's drop yaml/b64 in favor of the base64 encoder used everywhere else
in the Tarantool source code.

yaml/b64 is also used by serialize_lua to print MP_BIN values. Let's
print MP_BIN values as MP_STR there. This doesn't have any user-visible
changes because since commit 890a821c3be9 ("yaml: don't encode
unprintable strings as binary blobs") luaL_tofield never creates MP_BIN
values. However, when we introduce the varbinary type to Lua, we will
use the MP_BIN value type for it, and printing it in the Lua format as a
string with unprintable characters escaped is going to be less confusing
than encoding it in base64 without any tags or markers.

While we're at it, let's use the luaL_field.sval.data in the encoders
instead of extracting the string from the Lua stack again.

Needed for #1629

NO_DOC=refactoring
NO_TEST=refactoring
NO_CHANGELOG=refactoring
---
 third_party/lua-yaml/lyaml.cc | 12 +-----------
 1 file changed, 1 insertion(+), 11 deletions(-)

diff --git a/third_party/lua-yaml/lyaml.cc b/third_party/lua-yaml/lyaml.cc
index 90de31510f..ec7790403e 100644
--- a/third_party/lua-yaml/lyaml.cc
+++ b/third_party/lua-yaml/lyaml.cc
@@ -109,13 +109,6 @@ struct lua_yaml_dumper {
 static bool yaml_pretty_multiline = true;
 TWEAK_BOOL(yaml_pretty_multiline);
 
-/**
- * If this flag is set, a binary data field will be decoded to a plain Lua
- * string, not a varbinary object.
- */
-static bool yaml_decode_binary_as_string = false;
-TWEAK_BOOL(yaml_decode_binary_as_string);
-
 /**
  * Verify whether a string represents a boolean literal in YAML.
  *
@@ -288,10 +281,7 @@ static void load_scalar(struct lua_yaml_loader *loader) {
          int bufsize = base64_decode_bufsize(length);
          char *buf = (char *)xmalloc(bufsize);
          int size = base64_decode(str, length, buf, bufsize);
-         if (yaml_decode_binary_as_string)
-            lua_pushlstring(loader->L, buf, size);
-         else
-            luaT_pushvarbinary(loader->L, buf, size);
+         lua_pushlstring(loader->L, buf, size);
          free(buf);
          return;
       }
-- 
GitLab