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 15, 2025
1 parent 8593695 commit e7cd88d
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 2 deletions.
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*&%%\`][^*&%%\`]*[^%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
96 changes: 95 additions & 1 deletion spec/03-plugins/04-file-log/02-schema_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe("Plugin: file-log (schema)", function()
},
----------------------------------------
{
name = "rejects invalid filename",
name = "rejects invalid filename includes *",
input = {
path = "/ovo*",
reopen = true
Expand All @@ -30,6 +30,100 @@ describe("Plugin: file-log (schema)", function()
}
},
----------------------------------------
{
name = "rejects invalid filename includes `",
input = {
path = "/ovo`",
reopen = true
},
output = nil,
error = {
config = {
path = "not a valid filename"
}
}
},
----------------------------------------
{
name = "rejects invalid filename includes &",
input = {
path = "test&thing",
reopen = true
},
output = nil,
error = {
config = {
path = "not a valid filename"
}
}
},
----------------------------------------
{
name = "rejects invalid filename includes %",
input = {
path = "test%thing",
reopen = true
},
output = nil,
error = {
config = {
path = "not a valid filename"
}
}
},
----------------------------------------
{
name = "rejects invalid filename includes \\",
input = {
path = "test\\thing",
reopen = true
},
output = nil,
error = {
config = {
path = "not a valid filename"
}
}
},
----------------------------------------
{
name = "beginning spaces are not allowed",
input = {
path = " /ovo",
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 = "accept valid filename that includes space",
input = {
path = "/o vo.loga",
reopen = true
},
output = true,
error = nil,
},
------------------------------------
{
name = "accepts valid filename",
input = {
Expand Down

0 comments on commit e7cd88d

Please sign in to comment.