{"record":{"id":"f8ec1ba93af3a19a","repo":"can1357/oh-my-pi","slug":"ssh-does-not-support-url-fragments-percent-enc","errorCode":null,"errorMessage":"ssh:// does not support URL fragments; percent-encode a literal '#' as %23 in the path: ${url.href}","messagePattern":"ssh:// does not support URL fragments; percent-encode a literal '#' as %23 in the path: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/internal-urls/ssh-protocol.ts","lineNumber":84,"sourceCode":"\n/**\n * Remote absolute path from the URL. Uses `rawPathname` (pre-normalization) so\n * `..`/`//` and percent-escapes survive verbatim to the remote shell; the\n * authority (host/user/port) stays on the WHATWG fields, which preserve case for\n * the non-special `ssh` scheme.\n */\nfunction remotePathFromUrl(url: InternalUrl): string {\n\t// `?`/`#` are URL delimiters, so parseInternalUrl strips them from the path\n\t// (`ssh://h/tmp/a?draft` → `/tmp/a`). Reject the unsupported suffix instead of\n\t// silently operating on the truncated path; a literal `?`/`#` in a filename\n\t// must be percent-encoded (`%3F`/`%23`).\n\tif (url.search) {\n\t\tthrow new Error(\n\t\t\t`ssh:// does not support URL query strings; percent-encode a literal '?' as %3F in the path: ${url.href}`,\n\t\t);\n\t}\n\tif (url.hash) {\n\t\tthrow new Error(\n\t\t\t`ssh:// does not support URL fragments; percent-encode a literal '#' as %23 in the path: ${url.href}`,\n\t\t);\n\t}\n\tconst raw = url.rawPathname ?? url.pathname;\n\tlet decoded: string;\n\ttry {\n\t\tdecoded = decodeURIComponent(raw);\n\t} catch {\n\t\tthrow new Error(`Invalid URL encoding in ssh:// path: ${url.href}`);\n\t}\n\tif (!decoded) {\n\t\tthrow new Error(\n\t\t\t\"ssh:// requires an absolute path, e.g. ssh://host/etc/hosts or ssh://host/ for the root directory\",\n\t\t);\n\t}\n\treturn decoded;\n}\n","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/internal-urls/ssh-protocol.ts#L66-L102","documentation":"In a URL, `#` starts a fragment and the parser strips it and everything after it from the path. ssh:// remote paths have no fragment semantics, so the handler rejects any URL containing a fragment instead of silently operating on the truncated path; a literal `#` in a remote filename must be percent-encoded as `%23`.","triggerScenarios":"`SshProtocolHandler.resolve()` or `.write()` (via `remotePathFromUrl`) with a `ssh://` URL whose `url.hash` is non-empty, e.g. `ssh://host/etc/issue#1` or a filename like `notes#2.txt` passed unencoded.","commonSituations":"POSIX filenames containing `#` (common for scratch/versioned files like `config#backup`) used in ssh:// URLs; markdown-style anchor fragments appended by habit; copy-pasting paths containing `#` without encoding.","solutions":["Percent-encode the literal `#` as `%23`: `ssh://host/etc/config%23backup`.","Strip any fragment you appended for HTTP-style anchors — it has no meaning for ssh paths.","Rename the remote file to avoid `#` if encoding is inconvenient in your tooling."],"exampleFix":"// before\nawait readResource(\"ssh://host/docs/notes#2.txt\");\n// after\nawait readResource(\"ssh://host/docs/notes%232.txt\");","handlingStrategy":"validation","validationCode":"function assertNoSshFragment(url: string): void {\n  const u = new URL(url);\n  if (u.protocol === \"ssh:\" && u.hash) {\n    throw new Error(`ssh:// URL must not contain a fragment: ${url}`);\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  return await sshHandler.resolve(url);\n} catch (err) {\n  if (err instanceof Error && err.message.includes(\"does not support URL fragments\")) {\n    return sshHandler.resolve(parseInternalUrl(url.replaceAll(\"#\", \"%23\")));\n  }\n  throw err;\n}","preventionTips":["Encode literal '#' as %23 in ssh:// paths.","Strip markdown-style anchors before passing paths to ssh://.","Always percent-encode path segments built from variables.","Remember '#-containing filenames are valid on POSIX remote hosts."],"tags":["url","ssh-protocol","encoding"],"backgroundTag":"invalid-url-syntax","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}