fix(serial): linkify bare emulated-subnet IPs, not only http:// URLs

The serial monitor turns printed device URLs into IoT-gateway links —
but only when the sketch printed a full http:// URL. That matched the
Arduino idiom and missed MicroPython's: `print("Open:",
wlan.ifconfig()[0])` emits a bare "192.168.4.15", which rendered as
plain text. The address is unreachable from the host by design (it only
exists inside the emulated network), so exactly the users who just
gained real WiFi were handed an IP with no way to open it.

The scheme is now optional; a negative lookahead keeps longer
dotted strings (192.168.4.15.99) from half-matching. ifconfig() tuples
linkify every same-subnet address they contain — all of them route to
the same gateway root, so the extra links are harmless.
This commit is contained in:
David Montero Crespo 2026-08-10 22:11:04 +02:00
parent f96d239a1d
commit ea1cdffb56
1 changed files with 7 additions and 1 deletions

View File

@ -286,7 +286,13 @@ export const SerialMonitor: React.FC = () => {
// ESP32 (QEMU slirp) hands out 192.168.4.x; the Pico W virtual
// net hands out 10.13.37.x. Both reach their emulated server
// through the same /api/gateway proxy, so linkify either subnet.
const ipRegex = /http:\/\/(?:192\.168\.4|10\.13\.37)\.(\d+)(\/[^\s]*)?/g;
// The http:// prefix is OPTIONAL: Arduino sketches tend to print
// full URLs, but MicroPython's idiom is the bare ifconfig()[0]
// ("Open: 192.168.4.15") — requiring the scheme left exactly
// those users with a dead-end IP that is unreachable outside
// the emulated network. The trailing dot-check keeps a longer
// address like 192.168.4.15.99 from half-matching.
const ipRegex = /(?:http:\/\/)?(?:192\.168\.4|10\.13\.37)\.(\d{1,3})(?!\d|\.\d)(\/[^\s]*)?/g;
const matches = [...text.matchAll(ipRegex)];
if (matches.length > 0) {