From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id A80AF6B975; Tue, 13 Apr 2021 16:36:34 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org A80AF6B975 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1618320994; bh=1pZJb1gKAegpk1iq6Juad1QgQjQzM5PGU0YTr92fOnA=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=uYQHvfJ8mC1iGCSEqIVdxDta4zBEIXXFr2NAp2LPPkqfjsEDUEmg3bMRdfDgJg7Ac cV4XG54pEHGlvwEpuNas8dg1uS6um6D8E0lgpEfSQd6FzT6gcyvQ1ZpM8Da4xbu8zo bxxeGXrjdBZwziX56NTS3XfHK8uIusWAK1LGlPsY= Received: from smtp48.i.mail.ru (smtp48.i.mail.ru [94.100.177.108]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 373316B961 for ; Tue, 13 Apr 2021 16:28:49 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 373316B961 Received: by smtp48.i.mail.ru with esmtpa (envelope-from ) id 1lWJ60-0000dj-82; Tue, 13 Apr 2021 16:28:48 +0300 To: Sergey Ostanevich , Igor Munkin Date: Tue, 13 Apr 2021 16:27:16 +0300 Message-Id: <03646b43769edae6838b79b88cb8ecbedb2becbe.1618320000.git.skaplun@tarantool.org> X-Mailer: git-send-email 2.31.0 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD92FFCB8E6708E7480257C85EA0BB7A95D5E28B957962BB550182A05F538085040CECA471E0D0ECB45AFD719CBB8041B791226BE90808A5CF49A053FCC22BACFAA X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE792C68BF9CD4C0E9EEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006378997215BCAA11D778638F802B75D45FF914D58D5BE9E6BC1A93B80C6DEB9DEE97C6FB206A91F05B284D23BD2DB232384556007E368978EEBCB629EEF1311BF91D2E47CDBA5A96583C09775C1D3CA48CFA7AC412AE061D850117882F4460429724CE54428C33FAD30A8DF7F3B2552694AC26CFBAC0749D213D2E47CDBA5A9658378DA827A17800CE74F330F0740BBDD1F9FA2833FD35BB23DF004C906525384302BEBFE083D3B9BA73A03B725D353964B0B7D0EA88DDEDAC722CA9DD8327EE4933F735096452955E3A3CCBC2573AEBDE1C4224003CC83647689D4C264860C145E X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8183414BA6AC50EE020542CA1B392C39BBDB69F9342289A40B3CA740BBFFDA0FF3FBD0D09F98ACFCD8D9C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EF0417BEADF48D1460699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34AC632F0BE69382F3CAC8BEF441DF5B1A98C93C3EEED3FEB601767C0465D87B290DD2448F3352B6511D7E09C32AA3244C197889E2430993888B5231A279B4A92697FE24653F78E668927AC6DF5659F194 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojnA7/qPBUIXHVUlB1gcKTrQ== X-Mailru-Sender: 3B9A0136629DC91206CBC582EFEF4CB4BDBD760C04416CA30CB0C4669B49AB2C91BCE5B24AED1BADF2400F607609286E924004A7DEC283833C7120B22964430C52B393F8C72A41A89437F6177E88F7363CDA0F3B3F5B9367 X-Mras: Ok Subject: [Tarantool-patches] [PATCH luajit v3 16/29] test: adapt PUC-Rio test for %q in string.format X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Sergey Kaplun via Tarantool-patches Reply-To: Sergey Kaplun Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" LuaJIT since v2.0.0-beta6 has extension from Lua 5.2: string.format(): %q reversible. See also https://luajit.org/extensions.html#lua52. The q option formats a string in a form suitable to be safely read back by the Lua interpreter [1]. In Lua 5.1, '\0' was converted to "\000" unconditionally. In Lua 5.2, control characters are written as \nnn when needed, see d62a21b9d379a576bae7426c80039ca1a4d2bb07 ("when formatting with '%q', all control characters are coded as \nnn.") [1]. In this patch, %q specifier starts writing control characters to a new string in the same way through \d, instead of their binary representation as it is. If the control character is followed by a digit, then for the correct work of the parser, it is necessary to extend the escape sequence to 3 significant characters (otherwise, the transition "\0002" -> "\02" corrupts string). For this patch, the expansion is performed unconditionally (the check for the next symbol is not performed) if this first symbol is a zero byte. Consistent work with the zero byte processing omitting the custom check was added in the commit 658ea8752b979102627e2fede7b7ddfbb67ba6c9 ("no need to handle '\0' differently from other control chars in format '%q'") [2]. Note, that this patch does not change the semantics of %q specifier - the new string can still be "safely read back by the Lua interpreter". [1]: https://www.lua.org/manual/5.1/manual.html#pdf-string.format [2]: https://github.com/lua/lua/commit/d62a21b9d379a576bae7426c80039ca1a4d2bb07 [3]: https://github.com/lua/lua/commit/658ea8752b979102627e2fede7b7ddfbb67ba6c9 This patch adapts test for LuaJIT and Lua 5.2 behaviour considering the test from Lua 5.2 test suite taken from https://www.lua.org/tests/lua-5.2.0-tests.tar.gz. Resolves tarantool/tarantool#5710 Part of tarantool/tarantool#5845 Part of tarantool/tarantool#4473 --- test/PUC-Rio-Lua-5.1-tests/strings.lua | 38 +++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/test/PUC-Rio-Lua-5.1-tests/strings.lua b/test/PUC-Rio-Lua-5.1-tests/strings.lua index 237dbad3..0eee4c6e 100644 --- a/test/PUC-Rio-Lua-5.1-tests/strings.lua +++ b/test/PUC-Rio-Lua-5.1-tests/strings.lua @@ -102,7 +102,43 @@ print('+') x = '"ílo"\n\\' assert(string.format('%q%s', x, x) == '"\\"ílo\\"\\\n\\\\""ílo"\n\\') -assert(string.format('%q', "\0") == [["\000"]]) +--[[ +LuaJIT: LuaJIT since v2.0.0-beta6 has extension from Lua 5.2: +string.format(): %q reversible. + +The q option formats a string in a form suitable to be safely read +back by the Lua interpreter [1]. + +In Lua 5.1, '\0' was converted to "\000" unconditionally. + +In Lua 5.2, control characters are written as \nnn when needed, +see d62a21b9d379a576bae7426c80039ca1a4d2bb07 ("when formatting +with '%q', all control characters are coded as \nnn.") [1]. +In this patch, %q specifier starts writing control characters to +a new string in the same way through \d, instead of their binary +representation as it is. If the control character is followed by +a digit, then for the correct work of the parser, it is necessary +to extend the escape sequence to 3 significant characters +(otherwise, the transition "\0002" -> "\02" corrupts string). +For this patch, the expansion is performed unconditionally +(the check for the next symbol is not performed) if this first +symbol is a zero byte. + +Consistent work with the zero byte processing omitting the custom +check was added in the commit +658ea8752b979102627e2fede7b7ddfbb67ba6c9 ("no need to handle '\0' +differently from other control chars in format '%q'") [2]. Note, +that this patch does not change the semantics of %q specifier - +the new string can still be "safely read back by the Lua +interpreter". + +[1]: https://www.lua.org/manual/5.1/manual.html#pdf-string.format +[2]: https://github.com/lua/lua/commit/d62a21b9d379a576bae7426c80039ca1a4d2bb07 +[3]: https://github.com/lua/lua/commit/658ea8752b979102627e2fede7b7ddfbb67ba6c9 + +Test is adapted from PUC-Rio Lua 5.2 test suite. +--]] +assert(string.format('%q', "\0") == [["\0"]]) assert(string.format("\0%c\0%c%x\0", string.byte("á"), string.byte("b"), 140) == "\0á\0b8c\0") assert(string.format('') == "") -- 2.31.0