jackwener/OpenCLI · error · CommandExecutionError
LinkedIn company name has unexpected characters: ${slug}
Error message
LinkedIn company name has unexpected characters: ${slug} What it means
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.
Source
Thrown at clis/linkedin/company.js:41
let parsed;
try {
parsed = raw.startsWith('/') ? new URL(raw, `https://${LINKEDIN_DOMAIN}`) : new URL(raw);
} catch {
throw new CommandExecutionError(`LinkedIn company received a malformed URL: ${raw}`);
}
if (parsed.protocol !== 'https:' || parsed.username || parsed.password || parsed.port || !LINKEDIN_COMPANY_HOSTS.has(parsed.hostname.toLowerCase())) {
throw new CommandExecutionError('LinkedIn company URL must point to linkedin.com');
}
const m = parsed.pathname.match(COMPANY_URL_RE);
if (!m) throw new CommandExecutionError('LinkedIn company URL must look like /company/<name>');
try {
slug = decodeURIComponent(m[1]);
} catch {
throw new CommandExecutionError(`LinkedIn company URL has a malformed company slug: ${m[1]}`);
}
}
if (!SLUG_RE.test(slug)) {
throw new CommandExecutionError(`LinkedIn company name has unexpected characters: ${slug}`);
}
return `https://www.linkedin.com/company/${encodeURIComponent(slug)}/about/`;
}
function buildCompanyExtractionScript() {
return String.raw`(() => {
const clean = (s) => String(s || '').replace(/[ ]+/g, ' ').replace(/\s+/g, ' ').trim();
const facts = {};
for (const dt of Array.from(document.querySelectorAll('dt'))) {
const key = clean(dt.innerText || dt.textContent || '').toLowerCase().replace(/:$/, '');
const dd = dt.nextElementSibling;
const val = dd ? clean(dd.innerText || dd.textContent || '') : '';
if (key && val && !(key in facts)) facts[key] = val;
}
const name = clean((document.querySelector('main h1') || document.querySelector('h1'))?.innerText || '');
const bodyText = clean(document.body ? (document.body.innerText || '') : '');
const followersMatch = bodyText.match(/([\d,]+)\s+followers/i);
const aboutHeading = Array.from(document.querySelectorAll('main h2, section h2')).find((el) => /^About$|^Overview$/i.test(clean(el.innerText || '')));View on GitHub (pinned to 49907e53dc)
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
Example fix
// before
await company({ url: 'https://www.linkedin.com/company/Acme Corp' });
// after
await company({ url: 'https://www.linkedin.com/company/acme-corp/' }); Defensive patterns
Strategy: validation
Validate before calling
const SLUG_RE = /^[A-Za-z0-9][A-Za-z0-9\-_%.]*$/;
function 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; } }
if (!slugLooksValid(input)) throw new Error('Company slug contains unsupported characters'); Type guard
function isPlainSlug(s) { return typeof s === 'string' && /^[A-Za-z0-9][A-Za-z0-9\-_]*$/.test(s); } Try / catch
try {
const result = await company({ url: input });
} catch (err) {
if (String(err.message).includes('unexpected characters')) {
// derive the slug from the real LinkedIn page URL instead of the display name
} else throw err;
} Prevention
- 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
When it happens
Trigger: A decoded slug containing spaces (e.g. /company/acme%20corp), slashes (/company/a/b), CJK/emoji characters, or symbols like '&' passed as targetUrl.
Common situations: 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.
Related errors
- LinkedIn company URL must point to linkedin.com
- LinkedIn company URL must look like /company/<name>
- LinkedIn company URL has a malformed company slug: ${m[1]}
- LinkedIn post analytics expected an array of posts
- thread or recipient is required
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/f1b651510f3d52f9.
Report an issue: GitHub.