From de10c667667613e2df718ffbed072204ada2d630 Mon Sep 17 00:00:00 2001 From: yetone Date: Wed, 11 Nov 2026 19:50:56 +0800 Subject: [PATCH] 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 --- internal/gui/pageinline.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/internal/gui/pageinline.go b/internal/gui/pageinline.go index dac44038b..c04798b0e 100644 --- a/internal/gui/pageinline.go +++ b/internal/gui/pageinline.go @@ -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)]*?)\bsrc\s*=\s*(?:"([^"]*)"|'([^']*)')([^>]*)>\s*`) - inlineLink = regexp.MustCompile(`(?is)]*>`) - 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)`) + inlineScript = lazyre.New(`(?is)]*?)\bsrc\s*=\s*(?:"([^"]*)"|'([^']*)')([^>]*)>\s*`) + inlineLink = lazyre.New(`(?is)]*>`) + 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)`) ) // maxInlinePage bounds a page written as one document.