{"record":{"id":"e1a9ef11437b9fa1","repo":"jackwener/OpenCLI","slug":"weibo-delete-url-must-use-http-or-https","errorCode":null,"errorMessage":"weibo delete: URL must use http or https","messagePattern":"weibo delete: URL must use http or https","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/weibo/delete.js","lineNumber":21,"sourceCode":" */\nimport { cli, Strategy } from '@jackwener/opencli/registry';\nimport { ArgumentError, AuthRequiredError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';\nimport { requireObjectEvaluateResult, unwrapEvaluateResult } from './utils.js';\n\nconst WEIBO_HOST_RE = /(^|\\.)weibo\\.(com|cn)$/i;\nconst POST_ID_RE = /^[A-Za-z0-9]{4,32}$/;\n\nfunction normalizePostId(raw) {\n    const input = String(raw ?? '').trim();\n    if (!input) {\n        throw new ArgumentError('weibo delete: id cannot be empty');\n    }\n\n    let candidate = input;\n    try {\n        const url = new URL(input);\n        if (url.protocol !== 'http:' && url.protocol !== 'https:') {\n            throw new ArgumentError('weibo delete: URL must use http or https');\n        }\n        if (!WEIBO_HOST_RE.test(url.hostname)) {\n            throw new ArgumentError('weibo delete: URL must be a weibo.com or weibo.cn post URL');\n        }\n        const parts = url.pathname.split('/').filter(Boolean);\n        if (url.hostname.toLowerCase().endsWith('weibo.cn') && parts[0] === 'status') {\n            candidate = parts[1] ?? '';\n        } else {\n            candidate = parts.at(-1) ?? '';\n        }\n    } catch (error) {\n        if (error instanceof ArgumentError) throw error;\n    }\n\n    candidate = String(candidate ?? '').trim();\n    if (!POST_ID_RE.test(candidate)) {\n        throw new ArgumentError('weibo delete: id must be a numeric idstr, mblogid, or Weibo post URL');\n    }","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/weibo/delete.js#L3-L39","documentation":"If the id argument parses as a URL, normalizePostId requires it to use http: or https:. Any other scheme (ftp:, javascript:, weibo://, or a malformed string that URL still accepts like 'foo:bar') is rejected with ArgumentError to avoid resolving ids from non-web schemes.","triggerScenarios":"Passing a URL-like string with a non-http(s) scheme, e.g. `weibo delete --id 'weibo.com/123'` parsed with a relative scheme, or accidentally passing an internal/app scheme link copied from a mobile client.","commonSituations":"Pasting a link from the Weibo mobile app that uses a custom scheme, omitting the protocol and having URL parse it oddly, or typo'd schemes like htp://.","solutions":["Use a full https:// URL, e.g. https://weibo.com/1234567890/AbCdEfGhI","Or pass just the id (idstr or mblogid) instead of a URL — no scheme issues","Fix typos in the scheme (https:// not htp:// or http:/ )"],"exampleFix":"// before\nweibo delete --id 'weibo.com/user/AbCdEfGhI'\n// after\nweibo delete --id 'https://weibo.com/user/AbCdEfGhI'","handlingStrategy":"validation","validationCode":"function hasHttpScheme(u) {\n  try { const url = new URL(u); return url.protocol === 'http:' || url.protocol === 'https:'; }\n  catch { return false; }\n}\nif (!hasHttpScheme(input) && input.includes(':')) throw new Error('URL must use http or https');","typeGuard":"function isHttpUrl(v) {\n  if (typeof v !== 'string') return false;\n  try { const u = new URL(v); return u.protocol === 'http:' || u.protocol === 'https:'; }\n  catch { return false; }\n}","tryCatchPattern":"try {\n  await cliDelete({ id: input });\n} catch (err) {\n  if (err instanceof ArgumentError && /must use http or https/.test(err.message)) {\n    throw new Error('Use a full https:// URL or pass the bare id instead');\n  } else throw err;\n}","preventionTips":["Prefer passing the bare id over a URL to avoid scheme parsing entirely","Always include the full https:// prefix when passing URLs","Don't paste custom-scheme links from the Weibo mobile app","Sanitize inputs in wrapper scripts to strip stray schemes"],"tags":["weibo","argument-validation","url-parsing"],"backgroundTag":"invalid-url-scheme","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}