Skip to content

Commit

Permalink
fix(file-log): throw an error No such file or directory when the `p…
Browse files Browse the repository at this point in the history
…ath` has a whitespace at the beginning or end.
  • Loading branch information
raoxiaoyan committed Jan 13, 2025
1 parent 162a782 commit 3d0a077
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
message: "**file-log**: Fixed an issue where the path does not allow whitespace at the beginning or end."
type: bugfix
scope: Plugin
2 changes: 1 addition & 1 deletion kong/plugins/file-log/schema.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ return {
fields = {
{ path = { description = "The file path of the output log file. The plugin creates the log file if it doesn't exist yet.", type = "string",
required = true,
match = [[^[^*&%%\`]+$]],
match = [[^[^%s*&%%\\`]+$]],
err = "not a valid filename",
}, },
{ reopen = { description = "Determines whether the log file is closed and reopened on every request.", type = "boolean", required = true, default = false }, },
Expand Down
41 changes: 41 additions & 0 deletions spec/03-plugins/04-file-log/02-schema_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,47 @@ describe("Plugin: file-log (schema)", function()
}
},
----------------------------------------
{
name = "beginning spaces are not allowed",
input = {
path = " /ovo",
reopen = true
},
output = nil,
error = {
config = {
path = "not a valid filename"
}
}
},
{
name = "beginning spaces are not allowed",
input = {
path = "/ov\\o",
reopen = true
},
output = nil,
error = {
config = {
path = "not a valid filename"
}
}
},
----------------------------------------
{
name = "trailing spaces are not allowed",
input = {
path = "/ovo ",
reopen = true
},
output = nil,
error = {
config = {
path = "not a valid filename"
}
}
},
--------------------------------------
{
name = "accepts valid filename",
input = {
Expand Down

0 comments on commit 3d0a077

Please sign in to comment.