compat: switch json_escape_forward_slash to tweaks
This commit adds the json_escape_forward_slash variable and a tweak for it that is now used by the compat module. The new variable configures whether '/' is escaped when encoded in JSON. Note, the old implementation was quite messy so we had to rework it: - Drop luaL_serializer::encode_escape_forward_slash. This was an undocumented serializer option implemented only by the JSON serializer and used only by the compat module. Now, we use the json_escape_forward_slash global tweak for all JSON serializers instead, because making this tweak configurable per serializer doesn't make much sense. - Don't use mp_char2escape for escaping JSON characters. Historically, we used this table defined in libmsgpuck in the json_escape utility function. It equals the escape table used by the JSON encoder so it looks more reasonable to use the JSON encoder escape table in json_escape. This commit moves the JSON encoder escape table to util.c and adds an inline utility function json_escape_char which is now used by the JSON encoder and json_escape. - Drop an extra JSON escape table with '/' escaped. We had two escape tables in JSON, one with escaped '/' and another with unescaped '/'. Duplicating tables like this is error-prone and ugly. Let's use one table with '/' unescaped and check the json_escape_forward_slash flag in json_escape_char instead. The cost of this check is negligible performance-wise. This commit also drops the lua/compat.c source file, because it isn't used anymore. While we are at it, remove any mentions of MsgPack from the changelog entry for the json_escape_forward_slash compat option, because it isn't relevant anymore. Closes #8117 NO_DOC=refactoring NO_TEST=refactoring NO_CHANGELOG=refactoring
Showing
- changelogs/unreleased/gh-6200-lua_cjson-encode-escapes-slash.md 4 additions, 3 deletions...logs/unreleased/gh-6200-lua_cjson-encode-escapes-slash.md
- src/CMakeLists.txt 0 additions, 1 deletionsrc/CMakeLists.txt
- src/lib/core/util.c 54 additions, 6 deletionssrc/lib/core/util.c
- src/lua/compat.c 0 additions, 53 deletionssrc/lua/compat.c
- src/lua/compat.h 0 additions, 22 deletionssrc/lua/compat.h
- src/lua/compat.lua 1 addition, 7 deletionssrc/lua/compat.lua
- src/lua/init.c 0 additions, 2 deletionssrc/lua/init.c
- src/lua/serializer.c 0 additions, 14 deletionssrc/lua/serializer.c
- src/lua/serializer.h 0 additions, 10 deletionssrc/lua/serializer.h
- src/trivia/util.h 14 additions, 0 deletionssrc/trivia/util.h
- test/app-luatest/gh_6200_lua_cjson_escapes_slash_test.lua 5 additions, 9 deletionstest/app-luatest/gh_6200_lua_cjson_escapes_slash_test.lua
- third_party/lua-cjson/lua_cjson.c 1 addition, 84 deletionsthird_party/lua-cjson/lua_cjson.c
Loading
Please register or sign in to comment