From b85b6c64690dc75fd3096e452dbf8881456d0da7 Mon Sep 17 00:00:00 2001 From: Steffen Busch <37350514+steffenbusch@users.noreply.github.com> Date: Wed, 7 Aug 2024 21:39:15 +0200 Subject: replacer: `{file.*}` global placeholder strips trailing newline (#6411) Co-authored-by: Kanashimia --- replacer_test.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'replacer_test.go') diff --git a/replacer_test.go b/replacer_test.go index cf4d321b6..1c1a7048f 100644 --- a/replacer_test.go +++ b/replacer_test.go @@ -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() -- cgit v1.2.3