Allow hyphens in shortcode name
authorbep <bjorn.erik.pedersen@gmail.com>
Fri, 27 Feb 2015 10:57:23 +0000 (11:57 +0100)
committerbep <bjorn.erik.pedersen@gmail.com>
Fri, 27 Feb 2015 10:57:23 +0000 (11:57 +0100)
Fixes #929

hugolib/shortcode_test.go
hugolib/shortcodeparser.go

index 5df969f49d8df32f3403706507a61120ab8d5499..92089f64487a2152ced1c111330a9293dd98bf62 100644 (file)
@@ -33,6 +33,14 @@ func TestNonSC(t *testing.T) {
        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) {
        tem := tpl.New()
        tem.AddInternalShortcode("video.html", `Playing Video {{ .Get 0 }}`)
index 457c295c11a4992c8b5aeca60e52499f1b0c1cd9..5621a382f81b7f93148c27c837c842f1a5dbee18 100644 (file)
@@ -382,7 +382,7 @@ func lexShortcodeParam(l *pagelexer, escapedQuoteStart bool) stateFunc {
                        break
                }
 
-               if !isValidParamRune(r) {
+               if !isAlphaNumericOrHyphen(r) {
                        l.backup()
                        break
                }
@@ -477,7 +477,7 @@ func lexIdentifierInShortcode(l *pagelexer) stateFunc {
 Loop:
        for {
                switch r := l.next(); {
-               case isAlphaNumeric(r):
+               case isAlphaNumericOrHyphen(r):
                default:
                        l.backup()
                        word := l.input[l.start:l.pos]
@@ -541,7 +541,7 @@ func lexInsideShortcode(l *pagelexer) stateFunc {
                if l.peek() == '"' {
                        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()
                return lexShortcodeParam(l, false)
        case isAlphaNumeric(r):
@@ -584,7 +584,7 @@ func isSpace(r rune) bool {
        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)
        return isAlphaNumeric(r) || r == '-'
 }