Skip to content

Commit

Permalink
fix: json.encode在遇到字符串中的\n时会转义为\b,这是不合理的
Browse files Browse the repository at this point in the history
  • Loading branch information
wendal committed Jun 8, 2023
1 parent 0c13261 commit 4beac0b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion components/lua-cjson/lua_cjson.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ static const char* char2escape(unsigned char c) {
case 0x07: return "\\u0007";
case 0x08: return "\\b";
case 0x09: return "\\t";
case 0x0a: return "\\b";
case 0x0a: return "\\n";
case 0x0b: return "\\u000b";
case 0x0c: return "\\f";
case 0x0d: return "\\r";
Expand Down
7 changes: 7 additions & 0 deletions demo/json/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ sys.taskInit(function()
-- 限制小数点到1位
log.info("json", json.encode({abc=1234.300}, "1f"))

-- 2023.6.8 处理\n在encode之后变成\b的问题
local tmp = "ABC\r\nDEF\r\n"
local tmp2 = json.encode({str=tmp})
log.info("json", tmp2)
local tmp3 = json.decode(tmp2)
log.info("json", "tmp3", tmp3.str, tmp3.str == tmp)
-- break
end
end)

Expand Down

0 comments on commit 4beac0b

Please sign in to comment.