// Note that this in this setup is usually a descriptor constructed from a page,
// so we want to find the best match for that page.
-func (s descriptorHandler) compareDescriptors(category Category, this, other TemplateDescriptor) weight {
+func (s descriptorHandler) compareDescriptors(category Category, isEmbedded bool, this, other TemplateDescriptor) weight {
if this.LayoutMustMatch && this.Layout != other.Layout {
return weightNoMatch
}
- w := this.doCompare(category, other)
+ w := this.doCompare(category, isEmbedded, other)
+
if w.w1 <= 0 {
if category == CategoryMarkup && (this.Variant1 == other.Variant1) && (this.Variant2 == other.Variant2 || this.Variant2 != "" && other.Variant2 == "") {
// See issue 13242.
}
//lint:ignore ST1006 this vs other makes it easier to reason about.
-func (this TemplateDescriptor) doCompare(category Category, other TemplateDescriptor) weight {
+func (this TemplateDescriptor) doCompare(category Category, isEmbedded bool, other TemplateDescriptor) weight {
w := weightNoMatch
// HTML in plain text is OK, but not the other way around.
return w
}
- // If both are set and different, no match.
- if other.Variant2 != "" && this.Variant2 != "" && other.Variant2 != this.Variant2 {
- return w
+ if isEmbedded {
+ if other.Variant2 != "" && other.Variant2 != this.Variant2 {
+ return w
+ }
+ } else {
+ // If both are set and different, no match.
+ if other.Variant2 != "" && this.Variant2 != "" && other.Variant2 != this.Variant2 {
+ return w
+ }
}
const (
less := func(category Category, this, other1, other2 TemplateDescriptor) {
c.Helper()
- result1 := dh.compareDescriptors(category, this, other1)
- result2 := dh.compareDescriptors(category, this, other2)
+ result1 := dh.compareDescriptors(category, false, this, other1)
+ result2 := dh.compareDescriptors(category, false, this, other2)
c.Assert(result1.w1 < result2.w1, qt.IsTrue, qt.Commentf("%d < %d", result1, result2))
}
check := func(category Category, this, other TemplateDescriptor, less bool) {
c.Helper()
- result := dh.compareDescriptors(category, this, other)
+ result := dh.compareDescriptors(category, false, this, other)
if less {
c.Assert(result.w1 < 0, qt.IsTrue, qt.Commentf("%d", result))
} else {
b.ResetTimer()
for i := 0; i < b.N; i++ {
for _, pair := range pairs {
- _ = dh.compareDescriptors(CategoryLayout, pair.d1, pair.d2)
+ _ = dh.compareDescriptors(CategoryLayout, false, pair.d1, pair.d2)
}
}
}
distance := slashCountK1 - slashCountK2
for d2, vv := range v {
- weight := s.dh.compareDescriptors(CategoryBaseof, d1, d2)
+ weight := s.dh.compareDescriptors(CategoryBaseof, false, d1, d2)
weight.distance = distance
if best.isBetter(weight, vv.Template) {
best.updateValues(weight, k2, d2, vv.Template)
continue
}
- if vv.D.isKindInLayout(desc.Layout) && s.dh.compareDescriptors(CategoryBaseof, descBaseof, vv.D).w1 > 0 {
+ if vv.D.isKindInLayout(desc.Layout) && s.dh.compareDescriptors(CategoryBaseof, false, descBaseof, vv.D).w1 > 0 {
result = append(result, keyTemplateInfo{Key: k, Info: vv})
}
}
continue
}
- weight := s.dh.compareDescriptors(q.Category, q.Desc, k)
+ weight := s.dh.compareDescriptors(q.Category, vv.subCategory == SubCategoryEmbedded, q.Desc, k)
weight.distance = distance
if best.isBetter(weight, vv) {
best.updateValues(weight, k2, k, vv)
continue
}
- weight := s.dh.compareDescriptors(category, desc, k.d)
+ weight := s.dh.compareDescriptors(category, vv.subCategory == SubCategoryEmbedded, desc, k.d)
if best.isBetter(weight, vv) {
best.updateValues(weight, key, k.d, vv)
}
continue
}
- weight := s.dh.compareDescriptors(q.Category, q.Desc, k.d)
+ weight := s.dh.compareDescriptors(q.Category, vv.subCategory == SubCategoryEmbedded, q.Desc, k.d)
weight.distance = distance
isBetter := best.isBetter(weight, vv)
b.AssertFileContent("public/index.html", "<link rel=\"stylesheet\" href=\"/css/style.css\">")
}
+// Issue #13593.
+func TestNoGoat(t *testing.T) {
+ t.Parallel()
+
+ files := `
+-- hugo.toml --
+-- content/_index.md --
+---
+title: "Home"
+---
+
+§§§
+printf "Hello, world!"
+§§§
+
+-- layouts/all.html --
+{{ .Content }}
+
+`
+
+ b := hugolib.Test(t, files)
+
+ b.AssertFileContent("public/index.html", "Hello, world!")
+}
+
// Issue #13515
func TestPrintPathWarningOnDotRemoval(t *testing.T) {
t.Parallel()