Skip to content

Commit 9cd4df1

Browse files
bhaumanBruce Haumangveres
authored
Improve port parsing patterns to prevent FlowStorm false positives (#113)
* Improve port parsing patterns with case insensitivity and bounded whitespace - Add case-insensitive matching to port, Started, and Listening patterns - Use bounded whitespace (\s{1,10}) instead of unbounded (\s+) for predictability - Add optional space after colon in port number pattern (:\s?) - Add word boundary (\b) to port pattern to prevent false matches - Add regression test for FlowStorm output (issue #109) These changes maintain backward compatibility with all existing nREPL output formats while preventing false positives from FlowStorm's 'mem_reporter__4628' output that was matching the old regex. Co-authored-by: gveres <gveres@users.noreply.github.com> * Add word boundary before 'port' pattern for maximum strictness Per CodeRabbit review suggestion, add \b before 'port' to prevent edge cases like 'support 12345' or 'transport 12345', and restrict to 4-5 digits for consistency with other patterns. --------- Co-authored-by: Bruce Hauman <bhauman@gmail.com> Co-authored-by: gveres <gveres@users.noreply.github.com>
1 parent 19c071b commit 9cd4df1

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/clojure_mcp/nrepl_launcher.clj

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@
1515
Returns the port number as an integer or nil if not found."
1616
[output]
1717
(when output
18-
(let [patterns [#"(?i)nrepl.*?port[^\d]*(\d+)" ; nREPL server started on port 12345
19-
#"(?i)port[^\d]*(\d+)" ; port 12345, port: 12345
20-
#":(\d{4,5})\b" ; :12345 (4-5 digit ports)
21-
#"Started.*?(\d{4,5})\b" ; Started on 12345
22-
#"Listening.*?(\d{4,5})\b"] ; Listening on 12345
18+
(let [patterns [#"(?i)\bport\s{1,10}(\d{4,5})\b" ; port 12345
19+
#":\s?(\d{4,5})\b" ; :12345 or : 12345 (4-5 digit ports)
20+
#"(?i)Started on\s{1,10}(\d{4,5})\b" ; Started on 12345
21+
#"(?i)Listening on\s{1,10}(\d{4,5})\b"] ; Listening on 12345
2322
line (str/trim output)]
2423
(some (fn [pattern]
2524
(when-let [match (re-find pattern line)]

test/clojure_mcp/nrepl_launcher_test.clj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
"port abc" ; non-numeric
2727
"port 123" ; too small (below 1024)
2828
"port 999999" ; too large (above 65535)
29-
"random text"))
29+
"random text"
30+
;; FlowStorm output should not match (issue #109)
31+
"flow_storm.jobs$run_jobs$mem_reporter__4628@348137e8 function scheduled every 1000 millis"))
3032

3133
(testing "handles case insensitive matching"
3234
(are [output expected] (= expected (launcher/parse-port-from-output output))

0 commit comments

Comments
 (0)