Watch
0
0
Fork
You've already forked hyperhive
0

swarm-ui: open the terminal, group and flow pages for a malformed address

A name or id that isn't valid percent-encoding (for example /agents/%E0%A4%A/terminal)
made decodeURIComponent throw while the page rendered, leaving a blank page. The
segment now stays as typed, as the agents page already did, so the page opens
(a terminal for that name, disconnected). A tested helper does the decoding.
This commit is contained in:
iris 2026-11-25 19:58:30 +01:00 • committed by mara
commit 79f2d4bd4d
4 changed files with 30 additions and 6 deletions

View file

@ -32,6 +32,7 @@ import {
import { fetchJson, usePolled } from "../../ui/polled/usePolled.js";
import { useTermGroups } from "../../agent/terminal/useTermGroups.js";
import { useDynamicTabs } from "../../shell/useDynamicTabs.js";
import { safeDecode } from "../../shell/routes.js";
import { Button } from "../../ui/button/Button.js";
import { PaneDropTarget } from "../../ui/pane-tree/PaneDropTarget.js";
import { PaneTree } from "../../ui/pane-tree/PaneTree.js";
@ -40,7 +41,7 @@ import "./AgentGroupPage.css";
export function AgentGroupPage({
params,
}: RouteComponentProps<{ id: string }>) {
const id = decodeURIComponent(params.id);
const id = safeDecode(params.id);
const href = groupHref(id);
const groups = useTermGroups();
const group = groups.find(id);

View file

@ -28,6 +28,7 @@ import {
} from "../../agent/terminal/split-layout.js";
import { useTermGroups } from "../../agent/terminal/useTermGroups.js";
import { useDynamicTabs } from "../../shell/useDynamicTabs.js";
import { safeDecode } from "../../shell/routes.js";
import { PaneDropTarget } from "../../ui/pane-tree/PaneDropTarget.js";
import "./AgentTerminalPage.css";
@ -38,11 +39,9 @@ export function AgentTerminalPage({
params,
}: RouteComponentProps<{ name: string; subagent?: string }>) {
const { open } = useDynamicTabs();
const name = decodeURIComponent(params.name);
const name = safeDecode(params.name);
const subagent =
params.subagent === undefined
? undefined
: decodeURIComponent(params.subagent);
params.subagent === undefined ? undefined : safeDecode(params.subagent);
const { page, label } = termPaths(name, subagent);
// A subagent has no icon of its own: its tab wears its agent's.
useAgentFavicon(name);

View file

@ -13,6 +13,7 @@
// on top of the latest.
import { useCallback, useEffect, useState } from "preact/hooks";
import { usePageTitle } from "../../shell/page-title.js";
import { safeDecode } from "../../shell/routes.js";
import {
Link,
useLocation,
@ -71,7 +72,7 @@ export function FlowEditorPage({
// The page for a flow not saved yet, which has no flow id.
isNew?: boolean;
}) {
const flowId = decodeURIComponent(params.flowId);
const flowId = safeDecode(params.flowId);
const search = new URLSearchParams(useSearch());
const from = search.get("from");
// With `from` an archetype flow: the one agent this copy is for.

View file

@ -28,6 +28,19 @@ export function isFullBleedRoute(location: string): boolean {
// which starts a terminal group's path (`/agents/group/:id`).
const SELECTED_AGENT_PATTERN = /^\/agents\/([^/]+)$/;
/**
* A path segment as text. A segment that isn't valid percent-encoding (a typed
* or mangled address) comes back as it is, so a page can say "no such agent"
* rather than throwing while it renders.
*/
export function safeDecode(segment: string): string {
try {
return decodeURIComponent(segment);
} catch {
return segment;
}
}
/** The agent a path selects on the agents page, or `null` for any other path. */
export function selectedAgent(location: string): string | null {
const match = SELECTED_AGENT_PATTERN.exec(location);