{"record":{"id":"43474d3a799df180","repo":"jackwener/OpenCLI","slug":"linkedin-company-received-a-malformed-url-raw","errorCode":null,"errorMessage":"LinkedIn company received a malformed URL: ${raw}","messagePattern":"LinkedIn company received a malformed URL: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/linkedin/company.js","lineNumber":27,"sourceCode":"\nconst SLUG_RE = /^[A-Za-z0-9%._-]+$/;\nconst COMPANY_URL_RE = /^\\/company\\/([^/?#]+)/;\nconst LINKEDIN_COMPANY_HOSTS = new Set(['linkedin.com', LINKEDIN_DOMAIN]);\n\n// Accept a bare universal name (`nvidia`), a `/company/<slug>` path, or a full\n// company URL, and return the canonical about-page URL.\nfunction normalizeCompanyUrl(value) {\n    const raw = normalizeWhitespace(value || '');\n    if (!raw) {\n        throw new CommandExecutionError('LinkedIn company requires a company universal name or URL');\n    }\n    let slug = raw;\n    if (/^https?:\\/\\//i.test(raw) || raw.startsWith('/company/')) {\n        let parsed;\n        try {\n            parsed = raw.startsWith('/') ? new URL(raw, `https://${LINKEDIN_DOMAIN}`) : new URL(raw);\n        } catch {\n            throw new CommandExecutionError(`LinkedIn company received a malformed URL: ${raw}`);\n        }\n        if (parsed.protocol !== 'https:' || parsed.username || parsed.password || parsed.port || !LINKEDIN_COMPANY_HOSTS.has(parsed.hostname.toLowerCase())) {\n            throw new CommandExecutionError('LinkedIn company URL must point to linkedin.com');\n        }\n        const m = parsed.pathname.match(COMPANY_URL_RE);\n        if (!m) throw new CommandExecutionError('LinkedIn company URL must look like /company/<name>');\n        try {\n            slug = decodeURIComponent(m[1]);\n        } catch {\n            throw new CommandExecutionError(`LinkedIn company URL has a malformed company slug: ${m[1]}`);\n        }\n    }\n    if (!SLUG_RE.test(slug)) {\n        throw new CommandExecutionError(`LinkedIn company name has unexpected characters: ${slug}`);\n    }\n    return `https://www.linkedin.com/company/${encodeURIComponent(slug)}/about/`;\n}\n","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/linkedin/company.js#L9-L45","documentation":"When the input looks like a URL (http(s):// or /company/ prefix) the library parses it with the URL constructor; if parsing throws (or the earlier structural checks fail), normalizeCompanyUrl rejects it with CommandExecutionError naming the raw input. It guards the URL-building step from garbage input.","triggerScenarios":"Passing a URL-looking string that new URL() cannot parse — e.g. 'http://', 'https://[bad', or a value the caller believed was a URL but contains stray characters/whitespace embedded mid-string.","commonSituations":"Copy-pasted URLs with typos or truncated protocol; data pipelines concatenating fields incorrectly; single quotes/brackets from template strings leaking into the URL; a slug like 'nvidia inc' that starts with '/' by mistake.","solutions":["Correct the URL in your input — it must parse, e.g. https://www.linkedin.com/company/nvidia/.","Pre-validate with `new URL(value, 'https://www.linkedin.com')` in a try/catch before calling.","If you meant a bare universal name, pass just the slug ('nvidia') instead of a malformed URL.","Trim/sanitize the value (strip quotes, brackets, embedded whitespace) before invoking."],"exampleFix":"// before\nawait run('linkedin company \"https://www.linkedin.com/company/nvidia'); // malformed\n// after\nconst url = raw.trim().replace(/\"/g, '');\ntry { new URL(url, 'https://www.linkedin.com'); } catch { return fallback; }\nawait run(`linkedin company ${url}`);","handlingStrategy":"validation","validationCode":"function safeCompanyUrl(raw) {\n  const v = String(raw || '').trim().replace(/[\"']/g, '');\n  try { new URL(v.startsWith('/') ? v : v, 'https://www.linkedin.com'); }\n  catch { throw new Error(`malformed LinkedIn company URL: ${v}`); }\n  return v;\n}","typeGuard":"function isParseableUrl(v) {\n  try { new URL(v, 'https://www.linkedin.com'); return true; } catch { return false; }\n}","tryCatchPattern":"try {\n  await run(`linkedin company ${raw}`);\n} catch (e) {\n  if (/malformed URL/.test(e.message)) {\n    // sanitize or fall back to bare slug form\n    return run(`linkedin company ${raw.replace(/[^\\w./:-]/g, '')}`);\n  }\n  throw e;\n}","preventionTips":["Trim and strip stray quotes/brackets from user-supplied URLs.","Pre-parse with new URL(value, base) before invoking the command.","Prefer bare slugs ('nvidia') when you don't have a full URL."],"tags":["validation","url-parsing","argument-error"],"backgroundTag":"malformed-url","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}