Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove backslash before slash when encoding #8684

Merged
merged 1 commit into from
Jan 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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":{}}

uran0sH marked this conversation as resolved.
Show resolved Hide resolved


=== 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