tpl/tplimpl/embedded: Prevent leading newline in sitemap template

Fixes #14977
This commit is contained in:
Bjørn Erik Pedersen
2026-06-01 15:32:41 +02:00
parent 4e17421ec2
commit 0f440460c8
3 changed files with 15 additions and 2 deletions
+10
View File
@@ -429,6 +429,16 @@ func (s *IntegrationTestBuilder) negate(match string) (string, bool) {
return match, negate
}
// AssertFileContentStartsWith asserts that the content of the given file starts with s.
func (s *IntegrationTestBuilder) AssertFileContentStartsWith(filename, prefix string) {
s.Helper()
content := strings.TrimSpace(s.FileContent(filename))
cm := qt.Commentf("File: %s Expect:\n%s Got:\n%s\nWith Space Visuals:\n%s", filename, prefix, content, util.VisualizeSpaces([]byte(content)))
var negate bool
prefix, negate = s.negate(prefix)
s.Assert(strings.HasPrefix(content, prefix), qt.Equals, !negate, cm)
}
func (s *IntegrationTestBuilder) AssertFileContent(filename string, matches ...string) {
s.Helper()
content := strings.TrimSpace(s.FileContent(filename))
+4 -1
View File
@@ -42,7 +42,10 @@ Doc2
b := Test(t, files)
b.AssertFileContent("public/sitemap.xml", " <loc>https://example.com/sect/doc1/</loc>", "doc2")
b.AssertFileContentStartsWith("public/sitemap.xml", `<?xml`) // Issue 14977
b.AssertFileContent("public/sitemap.xml",
"<loc>https://example.com/sect/doc1/</loc>", "doc2",
)
}
func TestSitemapMultilingual(t *testing.T) {