High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
fix: treat space-separated : and = as prose, not CSS, in the MCP query heuristic PIN-019
Luigi Agosti7375a399dc82
diff --git a/internal/mcp/handlers_helpers.go b/internal/mcp/handlers_helpers.goindex c847cfc4..4d79cd5b 100644--- a/internal/mcp/handlers_helpers.go+++ b/internal/mcp/handlers_helpers.go@@ -89,7 +89,7 @@ func looksLikeStructuredSelector(v string) bool {if strings.HasPrefix(v, "//") || strings.HasPrefix(v, "(//") {return true}- if strings.ContainsAny(v, "[]#:>+~") || strings.Contains(v, "=") {+ if strings.ContainsAny(v, "[]#>+~") || containsSpacelessAny(v, ":=") {return true}// Treat dot notation as CSS only when it looks like tag/class syntax,@@ -100,6 +100,26 @@ func looksLikeStructuredSelector(v string) bool {return false}+func containsSpacelessAny(v, chars string) bool {+ for i := 0; i < len(v); i++ {+ if !strings.ContainsRune(chars, rune(v[i])) {+ continue+ }+ if i > 0 && isASCIISpace(v[i-1]) {+ continue+ }+ if i+1 < len(v) && isASCIISpace(v[i+1]) {+ continue+ }+ return true+ }+ return false+}++func isASCIISpace(c byte) bool {+ return c == ' ' || c == '\t' || c == '\r' || c == '\n'+}+func hasASCIIAlpha(v string) bool {for i := 0; i < len(v); i++ {c := v[i]diff --git a/internal/mcp/handlers_helpers_test.go b/internal/mcp/handlers_helpers_test.goindex 621efe45..114b1c3b 100644--- a/internal/mcp/handlers_helpers_test.go+++ b/internal/mcp/handlers_helpers_test.go@@ -1,6 +1,10 @@package mcp-import "testing"+import (+ "testing"++ "github.com/mark3labs/mcp-go/mcp"+)// looksLikeStructuredSelector decides whether an MCP client's free-form `query`// is passed through as a selector or wrapped as semantic `find:` text. Anything@@ -23,13 +27,15 @@ func TestLooksLikeStructuredSelector(t *testing.T) {{"parenthesised xpath", "(//a)[1]", true},{"descendant combinator", "div > p", true},{"tag dot class", "button.primary", true},+ {"pseudo class colon has no surrounding space", "a:hover", true},+ {"attribute equals has no surrounding space", "input[type=text]", true},+ {"attribute selector with sibling combinator", "input[name=q] + label", true},- // Current behaviour: the punctuation test on line 92 has no- // whitespace guard, unlike the dot-notation branch below it, so- // prose containing these characters is routed to CSS.- {"prose with colon", "Sign up: it's free", true},- {"prose with equals", "name = value", true},- {"prose with plus", "Add + remove", true},+ {"prose colon is space separated", "Sign up: it's free", false},+ {"prose equals is space separated", "name = value", false},+ {"colon with a space only before it", "ready :go", false},+ {"equals with a space only after it", "name= value", false},+ {"prose plus stays CSS because combinators are space separated in CSS too", "Add + remove", true},}for _, tt := range tests {@@ -53,3 +59,29 @@ func TestHasKnownSelectorPrefixIsCaseInsensitive(t *testing.T) {}}}++func TestActionSelectorArgRoutesSpaceSeparatedProseToFind(t *testing.T) {+ tests := []struct {+ name string+ query string+ want string+ }{+ {"prose colon is space separated", "Sign up: it's free", "find:Sign up: it's free"},+ {"prose equals is space separated", "name = value", "find:name = value"},+ {"pseudo class colon has no surrounding space", "a:hover", "a:hover"},+ {"attribute equals has no surrounding space", "input[type=text]", "input[type=text]"},+ {"attribute selector with sibling combinator", "input[name=q] + label", "input[name=q] + label"},+ {"descendant combinator", "div > p", "div > p"},+ {"prose plus stays CSS because combinators are space separated in CSS too", "Add + remove", "Add + remove"},+ }++ for _, tt := range tests {+ t.Run(tt.name, func(t *testing.T) {+ req := mcp.CallToolRequest{}+ req.Params.Arguments = map[string]any{"query": tt.query}+ if got := actionSelectorArg(req); got != tt.want {+ t.Errorf("actionSelectorArg(%q) = %q, want %q", tt.query, got, tt.want)+ }+ })+ }+}