fix(embeds): address Phase 38 review findings across registry, Blog Editor, and docs

This commit is contained in:
Jakub Zych
2026-11-28 13:13:09 +01:00
parent 3fc656da0f
commit a047d4284f
9 changed files with 69 additions and 37 deletions

View File

@@ -27,6 +27,13 @@ var (
embedAspectPattern = regexp.MustCompile(`^[1-9][0-9]{0,3}(?:\s*/\s*[1-9][0-9]{0,3}|\.[0-9]{1,4})?$`)
embedHeightPattern = regexp.MustCompile(`^[1-9][0-9]{0,3}(?:px)?$`)
// reservedEmbedProviderKeys mirrors vue-journal-layer's prototype-property
// guard so Go, Blog Editor, and Nuxt enforce the exact same key allow-list.
reservedEmbedProviderKeys = map[string]bool{
"constructor": true,
"prototype": true,
}
// defaultEmbedRegistry is the immutable youtube-only registry used when
// callers invoke package-level HTML helpers without a backpack.App.
defaultEmbedRegistry = NewEmbedRegistry()
@@ -97,8 +104,8 @@ func (r *EmbedRegistry) Register(p EmbedProvider) error {
return fmt.Errorf("embed provider: registry is nil")
}
p.Key = strings.TrimSpace(p.Key)
if !embedProviderKeyPattern.MatchString(p.Key) {
return fmt.Errorf("embed provider %q: key must match %s", p.Key, embedProviderKeyPattern.String())
if !embedProviderKeyPattern.MatchString(p.Key) || reservedEmbedProviderKeys[p.Key] {
return fmt.Errorf("embed provider %q: key must match %s and must not be a reserved name", p.Key, embedProviderKeyPattern.String())
}
p.IDPattern = strings.TrimSpace(p.IDPattern)
if p.IDPattern == "" {

View File

@@ -127,6 +127,8 @@ journal:
}{
{"path traversal key", EmbedProvider{Key: "../x", IDPattern: `^[a-z]+$`}, "../x"},
{"uppercase key", EmbedProvider{Key: "YouTube", IDPattern: `^[a-z]+$`}, "YouTube"},
{"reserved constructor key", EmbedProvider{Key: "constructor", IDPattern: `^[a-z]+$`}, "constructor"},
{"reserved prototype key", EmbedProvider{Key: "prototype", IDPattern: `^[a-z]+$`}, "prototype"},
{"empty key", EmbedProvider{Key: "", IDPattern: `^[a-z]+$`}, `""`},
{"missing pattern", EmbedProvider{Key: "viz", IDPattern: ""}, "viz"},
{"invalid regex", EmbedProvider{Key: "viz", IDPattern: `[unclosed`}, "viz"},