mirror of
https://github.com/gohugoio/hugo.git
synced 2026-08-24 15:28:54 +00:00
tpl/tplimpl/embedded: Prevent leading newline in sitemap template
Fixes #14977
This commit is contained in:
@@ -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))
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
{{/* gotmplfmt-ignore-all */}}
|
||||
{{/* gotmplfmt-ignore-all */ -}}
|
||||
{{ printf "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>" | safeHTML }}
|
||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
|
||||
xmlns:xhtml="http://www.w3.org/1999/xhtml">
|
||||
|
||||
Reference in New Issue
Block a user