diff --git a/README.md b/README.md
index 8b2cd1e..d9bc05f 100644
--- a/README.md
+++ b/README.md
@@ -131,7 +131,7 @@ If Zas finds an embed tag with a type attribute set to `text/yaml+myplugin`, it
```
-Maybe you are asking yourself: "Where is mzsmarkdown?". Nowhere! It is a particular case where Zas calls an exported method Markdown. I wanted to allow anyone to override internal Markdown processing if they wish.
+Maybe you are asking yourself: "Where is mzsmarkdown?". Nowhere! It is a particular case where Zas has a built-in handler for it. I wanted to allow anyone to override internal Markdown processing if they wish.
If you develop a new plugin, please contact me, and I will list it here :) Please, keep in mind: make it [idempotent](http://en.wikipedia.org/wiki/Idempotence).
diff --git a/embed_containment_test.go b/embed_containment_test.go
index 5fda1f6..cb29d99 100644
--- a/embed_containment_test.go
+++ b/embed_containment_test.go
@@ -27,9 +27,9 @@ type embedHandlerCase struct {
}
var embedHandlerCases = []embedHandlerCase{
- {"Markdown", "text/markdown", "note.md", "# Note\n\nHello from markdown.\n", (*Generator).Markdown, "Hello from markdown."},
- {"Plain", "text/plain", "note.txt", "hello from plain", (*Generator).Plain, "hello from plain"},
- {"Html", "text/html", "note.html", "
hello from html
", (*Generator).Html, "hello from html"},
+ {"Markdown", "text/markdown", "note.md", "# Note\n\nHello from markdown.\n", (*Generator).markdown, "Hello from markdown."},
+ {"Plain", "text/plain", "note.txt", "hello from plain", (*Generator).plain, "hello from plain"},
+ {"Html", "text/html", "note.html", "hello from html
", (*Generator).html, "hello from html"},
}
func embedDocFor(t *testing.T, src, typ string) *goquery.Document {
diff --git a/embed_dispatch_test.go b/embed_dispatch_test.go
index 9db4441..62014f4 100644
--- a/embed_dispatch_test.go
+++ b/embed_dispatch_test.go
@@ -1,39 +1,21 @@
package zas
import (
- "reflect"
"strings"
"testing"
"github.com/PuerkitoBio/goquery"
)
-// config data must not be able to pick an arbitrary Generator method via
-// reflection and panic method.Call with a mismatched arity/signature.
+// config data must not be able to pick an arbitrary Generator method for
+// embed dispatch - only the closed set embedPlugin knows about.
-func TestIsEmbedPluginMethod(t *testing.T) {
- gen := &Generator{}
-
- if valid := reflect.ValueOf(gen).MethodByName("Markdown"); !isEmbedPluginMethod(valid) {
- t.Fatal("isEmbedPluginMethod(Markdown) = false, want true")
- }
- // Run() error is a real exported Generator method, but with the wrong
- // arity (0 args) for embed dispatch - must be rejected, not panic.
- if wrongArity := reflect.ValueOf(gen).MethodByName("Run"); isEmbedPluginMethod(wrongArity) {
- t.Fatal("isEmbedPluginMethod(Run) = true, want false")
- }
- if notFound := reflect.ValueOf(gen).MethodByName("DoesNotExist"); isEmbedPluginMethod(notFound) {
- t.Fatal("isEmbedPluginMethod(missing method) = true, want false")
- }
-}
-
-func TestHandleEmbedTagsFallsBackOnWrongArityMethod(t *testing.T) {
- // Reproduces the audit repro: mimetypes: {text/x-t: run} resolves to the
- // real, exported Run() error method, which has the wrong signature for
- // embed dispatch. Must fall back to the external plugin path instead of
- // panicking in reflect.Value.Call. The fallback path itself is a no-op
- // here (see audit A1, out of scope), so simply completing without a
- // panic is the regression this guards.
+func TestHandleEmbedTagsFallsBackOnUnknownPluginName(t *testing.T) {
+ // mimetypes: {text/x-t: run} resolves to "run", which isn't one of
+ // embedPlugin's three known names (it happens to also be the name of a
+ // real, exported, wrong-signature Generator method, Run() error - but
+ // that's no longer relevant: embedPlugin never looks at Generator's
+ // actual method set). Must fall back to the external plugin path.
gen := &Generator{
Config: ConfigSection{
"mimetypes": ConfigSection{"text/x-t": "run"},
diff --git a/generate.go b/generate.go
index cf0f3e2..64c26e1 100644
--- a/generate.go
+++ b/generate.go
@@ -27,7 +27,6 @@ import (
"os"
"os/exec"
"path/filepath"
- "reflect"
"regexp"
"runtime"
"strings"
@@ -46,8 +45,6 @@ import (
yaml "go.yaml.in/yaml/v3"
html5 "golang.org/x/net/html"
"golang.org/x/net/html/atom"
- "golang.org/x/text/cases"
- "golang.org/x/text/language"
)
var helpers = thtml.FuncMap{
@@ -1475,8 +1472,8 @@ func (gen *Generator) resolveEmbedSrc(baseDir, src string) (string, error) {
}
// embedTargetModTime returns the latest mtime among path's own literal
-//