mirror of
https://github.com/gohugoio/hugo.git
synced 2025-02-18 09:53:16 +00:00
parent
967d001ebe
commit
176ce5deab
2 changed files with 12 additions and 4 deletions
|
@ -33,6 +33,14 @@ func TestNonSC(t *testing.T) {
|
||||||
CheckShortCodeMatch(t, "{{%/* movie 47238zzb */%}}", "{{% movie 47238zzb %}}", tem)
|
CheckShortCodeMatch(t, "{{%/* movie 47238zzb */%}}", "{{% movie 47238zzb %}}", tem)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Issue #929
|
||||||
|
func TestHyphenatedSC(t *testing.T) {
|
||||||
|
tem := tpl.New()
|
||||||
|
tem.AddInternalShortcode("hyphenated-video.html", `Playing Video {{ .Get 0 }}`)
|
||||||
|
|
||||||
|
CheckShortCodeMatch(t, "{{< hyphenated-video 47238zzb >}}", "Playing Video 47238zzb", tem)
|
||||||
|
}
|
||||||
|
|
||||||
func TestPositionalParamSC(t *testing.T) {
|
func TestPositionalParamSC(t *testing.T) {
|
||||||
tem := tpl.New()
|
tem := tpl.New()
|
||||||
tem.AddInternalShortcode("video.html", `Playing Video {{ .Get 0 }}`)
|
tem.AddInternalShortcode("video.html", `Playing Video {{ .Get 0 }}`)
|
||||||
|
|
|
@ -382,7 +382,7 @@ func lexShortcodeParam(l *pagelexer, escapedQuoteStart bool) stateFunc {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
if !isValidParamRune(r) {
|
if !isAlphaNumericOrHyphen(r) {
|
||||||
l.backup()
|
l.backup()
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -477,7 +477,7 @@ func lexIdentifierInShortcode(l *pagelexer) stateFunc {
|
||||||
Loop:
|
Loop:
|
||||||
for {
|
for {
|
||||||
switch r := l.next(); {
|
switch r := l.next(); {
|
||||||
case isAlphaNumeric(r):
|
case isAlphaNumericOrHyphen(r):
|
||||||
default:
|
default:
|
||||||
l.backup()
|
l.backup()
|
||||||
word := l.input[l.start:l.pos]
|
word := l.input[l.start:l.pos]
|
||||||
|
@ -541,7 +541,7 @@ func lexInsideShortcode(l *pagelexer) stateFunc {
|
||||||
if l.peek() == '"' {
|
if l.peek() == '"' {
|
||||||
return lexShortcodeParam(l, true)
|
return lexShortcodeParam(l, true)
|
||||||
}
|
}
|
||||||
case l.elementStepNum > 0 && (isValidParamRune(r) || r == '"'): // positional params can have quotes
|
case l.elementStepNum > 0 && (isAlphaNumericOrHyphen(r) || r == '"'): // positional params can have quotes
|
||||||
l.backup()
|
l.backup()
|
||||||
return lexShortcodeParam(l, false)
|
return lexShortcodeParam(l, false)
|
||||||
case isAlphaNumeric(r):
|
case isAlphaNumeric(r):
|
||||||
|
@ -584,7 +584,7 @@ func isSpace(r rune) bool {
|
||||||
return r == ' ' || r == '\t'
|
return r == ' ' || r == '\t'
|
||||||
}
|
}
|
||||||
|
|
||||||
func isValidParamRune(r rune) bool {
|
func isAlphaNumericOrHyphen(r rune) bool {
|
||||||
// let unquoted YouTube ids as positional params slip through (they contain hyphens)
|
// let unquoted YouTube ids as positional params slip through (they contain hyphens)
|
||||||
return isAlphaNumeric(r) || r == '-'
|
return isAlphaNumeric(r) || r == '-'
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue