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:
parent
c7e559a09e
commit
79f2d4bd4d
1 changed files with 30 additions and 6 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in a new issue