feat: remove restriction of label pattern to support Chinese (#3379)

* feat: remove restriction of label pattern to support Chinese

Fix #3378.

Signed-off-by: spacewander <spacewanderlzx@gmail.com>

* whitespace

Signed-off-by: spacewander <spacewanderlzx@gmail.com>
This commit is contained in:
罗泽轩 2021-01-21 07:27:00 -06:00 committed by GitHub
parent 62b5f7c6d4
commit 64029e0ecc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 94 additions and 1 deletions

View File

@ -81,7 +81,7 @@ local remote_addr_def = {
local label_value_def = {
description = "value of label",
type = "string",
pattern = [[^[a-zA-Z0-9-_.]+$]],
pattern = [[^\S+$]],
maxLength = 64,
minLength = 1
}

View File

@ -518,3 +518,96 @@ GET /t
{"error_msg":"only one of remote_addr or remote_addrs is allowed"}
--- no_error_log
[error]
=== TEST 15: labels in Chinese
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/routes/1',
ngx.HTTP_PUT,
[[{
"methods": ["GET"],
"upstream": {
"nodes": {
"127.0.0.1:8080": 1
},
"type": "roundrobin"
},
"labels": {
"您好": "世界"
},
"uri": "/index.html"
}]],
[[{
"node": {
"value": {
"methods": [
"GET"
],
"uri": "/index.html",
"upstream": {
"nodes": {
"127.0.0.1:8080": 1
},
"type": "roundrobin"
},
"labels": {
"您好": "世界"
}
},
"key": "/apisix/routes/1"
},
"action": "set"
}]]
)
ngx.status = code
ngx.say(body)
}
}
--- request
GET /t
--- response_body
passed
--- no_error_log
[error]
=== TEST 16: labels value with whitespace
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/routes/1',
ngx.HTTP_PUT,
[[{
"methods": ["GET"],
"upstream": {
"nodes": {
"127.0.0.1:8080": 1
},
"type": "roundrobin"
},
"labels": {
"您好": "世 界"
},
"uri": "/index.html"
}]]
)
ngx.status = code
ngx.say(body)
}
}
--- request
GET /t
--- error_code: 400
--- response_body_like eval
qr/invalid configuration: property \\"labels\\" validation failed/
--- no_error_log
[error]