)
const (
- identifierBaseof = "baseof"
- identifierCurstomWrapper = "_"
+ identifierBaseof = "baseof"
+ identifierCustomWrapper = "_"
)
+// isCustomWrapperIdentifier tells whether a supplied path is of the form _xyz_.
+// must have non-empty content between the identifierCustomWrapper's to pass.
+func isCustomWrapperIdentifier(s string) bool {
+ return len(s) > 2*len(identifierCustomWrapper) &&
+ strings.HasPrefix(s, identifierCustomWrapper) &&
+ strings.HasSuffix(s, identifierCustomWrapper)
+}
+
// PathParser parses and manages paths.
type PathParser struct {
// Maps the language code to its index in the languages/sites slice.
id := types.LowHigh[string]{Low: i + 1, High: high}
sid := p.s[id.Low:id.High]
- if strings.HasPrefix(sid, identifierCurstomWrapper) && strings.HasSuffix(sid, identifierCurstomWrapper) {
+ if isCustomWrapperIdentifier(sid) {
p.identifiersKnown = append(p.identifiersKnown, id)
p.posIdentifierCustom = len(p.identifiersKnown) - 1
found = true
}
func (p *Path) Custom() string {
- return strings.TrimSuffix(strings.TrimPrefix(p.identifierAsString(p.posIdentifierCustom), identifierCurstomWrapper), identifierCurstomWrapper)
+ return strings.TrimSuffix(strings.TrimPrefix(p.identifierAsString(p.posIdentifierCustom), identifierCustomWrapper), identifierCustomWrapper)
}
func (p *Path) Identifier(i int) string {
b.AssertFileContent("public/post/nested-a/content-a/index.html", `Content: http://example.com/post/nested-b/content-b/`)
}
+// Issue 14344
+func TestRefUnderscoreSection(t *testing.T) {
+ t.Parallel()
+
+ files := `
+-- hugo.toml --
+baseURL = 'https://example.org/'
+-- layouts/home.html --
+{{ .Content }}
+-- content/_index.md --
+---
+title: home
+---
+{{% ref "definitions/_" %}}
+-- content/definitions/_/_index.md --
+---
+title: underscore
+---
+`
+
+ b := Test(t, files)
+
+ b.AssertFileContent("public/index.html",
+ `https://example.org/definitions/_/`,
+ )
+}
+
func TestClassCollector(t *testing.T) {
for _, minify := range []bool{false, true} {
t.Run(fmt.Sprintf("minify-%t", minify), func(t *testing.T) {