replacer: {file.*} global placeholder strips trailing newline (#6411)

Co-authored-by: Kanashimia <chad@redpilled.dev>
This commit is contained in:
Steffen Busch
2024-08-07 21:39:15 +02:00
committed by GitHub
parent 59cbb2c83a
commit b85b6c6469
4 changed files with 21 additions and 0 deletions

View File

@@ -431,6 +431,14 @@ func TestReplacerNew(t *testing.T) {
variable: "file.caddytest/integration/testdata/foo.txt",
value: "foo",
},
{
variable: "file.caddytest/integration/testdata/foo_with_trailing_newline.txt",
value: "foo",
},
{
variable: "file.caddytest/integration/testdata/foo_with_multiple_trailing_newlines.txt",
value: "foo" + getEOL(),
},
} {
if val, ok := repl.providers[1].replace(tc.variable); ok {
if val != tc.value {
@@ -442,6 +450,13 @@ func TestReplacerNew(t *testing.T) {
}
}
func getEOL() string {
if os.PathSeparator == '\\' {
return "\r\n" // Windows EOL
}
return "\n" // Unix and modern macOS EOL
}
func TestReplacerNewWithoutFile(t *testing.T) {
repl := NewReplacer().WithoutFile()