gui: plugin page inlining compiles its regexps on first use (#6145)

55dff77b4 compiled seven package-level regexps in pageinline.go with
regexp.MustCompile, so TestNoEagerPackageRegexps was red on main. They
now go through lazyre.New, like the rest of internal/gui.

Ran on mica at this tree (origin/main 817ccb56f + this change):
- go test -run TestNoEagerPackageRegexps . : ok (red in the full suite
  log at 6b4513082 before)
- go test -tags nogui ./internal/gui -run 'Inline|PluginPage|Page': ok
- GOOS=linux go vet -tags nogui ./internal/gui, GOOS=windows go vet
  ./internal/gui: ok; gofmt clean
Not run: the full suite or GUI suite (the change is a constructor swap).

Fixes #6145
This commit is contained in:
yetone
2026-11-11 19:50:56 +08:00
parent 817ccb56f9
commit de10c66766
+8 -8
View File
@@ -5,9 +5,9 @@ import (
"encoding/base64"
"net/url"
"os"
"regexp"
"strings"
"github.com/yetone/magpie/internal/lazyre"
"github.com/yetone/magpie/internal/plugin"
)
@@ -26,13 +26,13 @@ import (
// asset call), which carries the cookie.
var (
inlineScript = regexp.MustCompile(`(?is)<script\b([^>]*?)\bsrc\s*=\s*(?:"([^"]*)"|'([^']*)')([^>]*)>\s*</script\s*>`)
inlineLink = regexp.MustCompile(`(?is)<link\b[^>]*>`)
attrRel = regexp.MustCompile(`(?is)\brel\s*=\s*["']?\s*stylesheet\b`)
attrHref = regexp.MustCompile(`(?is)\bhref\s*=\s*(?:"([^"]*)"|'([^']*)')`)
attrType = regexp.MustCompile(`(?is)\btype\s*=\s*["']?\s*([^"'\s>]*)`)
attrDefer = regexp.MustCompile(`(?is)\bdefer\b`)
bodyClose = regexp.MustCompile(`(?i)</body\s*>`)
inlineScript = lazyre.New(`(?is)<script\b([^>]*?)\bsrc\s*=\s*(?:"([^"]*)"|'([^']*)')([^>]*)>\s*</script\s*>`)
inlineLink = lazyre.New(`(?is)<link\b[^>]*>`)
attrRel = lazyre.New(`(?is)\brel\s*=\s*["']?\s*stylesheet\b`)
attrHref = lazyre.New(`(?is)\bhref\s*=\s*(?:"([^"]*)"|'([^']*)')`)
attrType = lazyre.New(`(?is)\btype\s*=\s*["']?\s*([^"'\s>]*)`)
attrDefer = lazyre.New(`(?is)\bdefer\b`)
bodyClose = lazyre.New(`(?i)</body\s*>`)
)
// maxInlinePage bounds a page written as one document.