{"record":{"id":"f1b651510f3d52f9","repo":"jackwener/OpenCLI","slug":"linkedin-company-name-has-unexpected-characters","errorCode":null,"errorMessage":"LinkedIn company name has unexpected characters: ${slug}","messagePattern":"LinkedIn company name has unexpected characters: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/linkedin/company.js","lineNumber":41,"sourceCode":"        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\nfunction buildCompanyExtractionScript() {\n    return String.raw`(() => {\n    const clean = (s) => String(s || '').replace(/[  ]+/g, ' ').replace(/\\s+/g, ' ').trim();\n    const facts = {};\n    for (const dt of Array.from(document.querySelectorAll('dt'))) {\n      const key = clean(dt.innerText || dt.textContent || '').toLowerCase().replace(/:$/, '');\n      const dd = dt.nextElementSibling;\n      const val = dd ? clean(dd.innerText || dd.textContent || '') : '';\n      if (key && val && !(key in facts)) facts[key] = val;\n    }\n    const name = clean((document.querySelector('main h1') || document.querySelector('h1'))?.innerText || '');\n    const bodyText = clean(document.body ? (document.body.innerText || '') : '');\n    const followersMatch = bodyText.match(/([\\d,]+)\\s+followers/i);\n    const aboutHeading = Array.from(document.querySelectorAll('main h2, section h2')).find((el) => /^About$|^Overview$/i.test(clean(el.innerText || '')));","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/linkedin/company.js#L23-L59","documentation":"After decoding, the slug must match SLUG_RE; characters outside the allowed set (spaces, slashes, most non-ASCII or symbols) cause this error. The library enforces LinkedIn's company-slug alphabet to avoid building a bogus about-page URL.","triggerScenarios":"A decoded slug containing spaces (e.g. /company/acme%20corp), slashes (/company/a/b), CJK/emoji characters, or symbols like '&' passed as targetUrl.","commonSituations":"Passing the company display name ('Acme Corp') instead of the URL slug ('acme-corp'); URL built from a page title rather than the actual LinkedIn slug; localized company names with non-Latin characters that LinkedIn slugs do not use.","solutions":["Use the actual LinkedIn slug from the page URL, not the display name (acme-corp, not 'Acme Corp')","Replace spaces with hyphens and strip unsupported characters before building the URL","Verify the slug in a browser: the URL that LinkedIn serves for the company is the valid form"],"exampleFix":"// before\nawait company({ url: 'https://www.linkedin.com/company/Acme Corp' });\n// after\nawait company({ url: 'https://www.linkedin.com/company/acme-corp/' });","handlingStrategy":"validation","validationCode":"const SLUG_RE = /^[A-Za-z0-9][A-Za-z0-9\\-_%.]*$/;\nfunction slugLooksValid(u) { try { const p = new URL(u); const m = p.pathname.match(/^\\/company\\/([^/]+)/); return !!m && SLUG_RE.test(decodeURIComponent(m[1])); } catch { return false; } }\nif (!slugLooksValid(input)) throw new Error('Company slug contains unsupported characters');","typeGuard":"function isPlainSlug(s) { return typeof s === 'string' && /^[A-Za-z0-9][A-Za-z0-9\\-_]*$/.test(s); }","tryCatchPattern":"try {\n  const result = await company({ url: input });\n} catch (err) {\n  if (String(err.message).includes('unexpected characters')) {\n    // derive the slug from the real LinkedIn page URL instead of the display name\n  } else throw err;\n}","preventionTips":["Use the actual LinkedIn slug (from the page URL), not the company display name","Normalize names to slugs: lowercase, spaces to hyphens, strip symbols","Check the URL renders the company in a browser before automating it"],"tags":["url-validation","linkedin","input-validation"],"backgroundTag":"invalid-url","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}