Skip to content

Commit

Permalink
fix: remove backslash before slash when encoding (#8684)
Browse files Browse the repository at this point in the history
Fixes #7785
  • Loading branch information
uran0sH authored Jan 18, 2023
1 parent b440a06 commit 4131fbf
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 5 deletions.
1 change: 1 addition & 0 deletions apisix/core/json.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ local pairs = pairs
local cached_tab = {}


cjson.encode_escape_forward_slash(false)
cjson.decode_array_with_array_mt(true)
local _M = {
version = 0.1,
Expand Down
2 changes: 1 addition & 1 deletion t/admin/api.t
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,4 @@ deployment:
X-API-KEY: edd1c9f034335f136f87ad84b625c8f1
--- response_headers
X-API-VERSION: v2
--- response_body_like: "\\/apisix\\/routes"
--- response_body_like: "/apisix/routes"
19 changes: 19 additions & 0 deletions t/core/json.t
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,22 @@ qr/\{"b":\{"a":\{"b":"table: 0x[\w]+"\}\}\}/
--- response_body
{"arr":[]}
{"obj":{}}
=== TEST 7: encode slash without escape
--- config
location /t {
content_by_lua_block {
local core = require("apisix.core")
local json_data = core.json.encode({test="/test"})
ngx.say("encode: ", json_data)
local data = core.json.decode(json_data)
ngx.say("data: ", data.test)
}
}
--- response_body
encode: {"test":"/test"}
data: /test
2 changes: 1 addition & 1 deletion t/gm/gm.t
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ location /t {
}
--- error_code: 400
--- response_body
{"error_msg":"sign cert\/key are required"}
{"error_msg":"sign cert/key are required"}
Expand Down
2 changes: 1 addition & 1 deletion t/plugin/ext-plugin/sanity.t
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ EXPIRE 3600
}
--- error_log
runner exited with reason: exit, status: 111
respawn runner 3 seconds later with cmd: ["t\/plugin\/ext-plugin\/runner.sh","0.1"]
respawn runner 3 seconds later with cmd: ["t/plugin/ext-plugin/runner.sh","0.1"]
Expand Down
2 changes: 1 addition & 1 deletion t/plugin/real-ip.t
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ __DATA__
--- response_body
{"error_msg":"failed to check the configuration of plugin real-ip err: property \"source\" is required"}
{"error_msg":"failed to check the configuration of plugin real-ip err: property \"trusted_addresses\" validation failed: failed to validate item 1: object matches none of the required"}
{"error_msg":"failed to check the configuration of plugin real-ip err: invalid ip address: ::1\/129"}
{"error_msg":"failed to check the configuration of plugin real-ip err: invalid ip address: ::1/129"}
Expand Down
2 changes: 1 addition & 1 deletion t/stream-node/sanity.t
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ hello world
GET /t
--- error_code: 400
--- response_body
{"error_msg":"invalid remote_addr: :\/8"}
{"error_msg":"invalid remote_addr: :/8"}



Expand Down

0 comments on commit 4131fbf

Please sign in to comment.