jackwener/OpenCLI · error · CommandExecutionError

LinkedIn company URL has a malformed company slug: ${m[1]}

Error message

LinkedIn company URL has a malformed company slug: ${m[1]}

What it means

The company slug captured from the URL path is percent-encoded; decodeURIComponent fails when it contains invalid escape sequences (e.g. a stray % not followed by two hex digits). The library treats such a slug as unusable and throws instead of passing a corrupt name downstream.

Source

Thrown at clis/linkedin/company.js:37

        throw new CommandExecutionError('LinkedIn company requires a company universal name or URL');
    }
    let slug = raw;
    if (/^https?:\/\//i.test(raw) || raw.startsWith('/company/')) {
        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;
    }

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Fix the URL so percent escapes are valid (e.g. /company/acme%2520corp for a literal %)
  2. Encode reserved characters properly: encodeURIComponent on dynamic slug parts before interpolating
  3. Remove the stray % or truncate trailing punctuation from the slug

Example fix

// before
const url = `https://www.linkedin.com/company/${raw}%`;
// after
const url = `https://www.linkedin.com/company/${encodeURIComponent(raw)}/`;
Defensive patterns

Strategy: validation

Validate before calling

function hasValidEncoding(u) { try { const p = new URL(u); return p.pathname.split('/').every(seg => { try { decodeURIComponent(seg); return true; } catch { return false; } }); } catch { return false; } }
if (!hasValidEncoding(input)) throw new Error('URL contains invalid percent-encodings');

Type guard

function isDecodableSlug(s) { try { decodeURIComponent(s); return true; } catch { return false; } }

Try / catch

try {
  const result = await company({ url: input });
} catch (err) {
  if (String(err.message).includes('malformed company slug')) {
    // rebuild the URL with encodeURIComponent on the dynamic slug
  } else throw err;
}

Prevention

When it happens

Trigger: targetUrl path containing a malformed percent-escape such as /company/acme%zz or /company/100% done; a slug produced by manual or broken encoding that inserted a lone % character.

Common situations: Double-encoding or hand-truncating a URL so '%25' becomes '%'; copy/paste from a document that mangled the escape; templating code that inserted a raw '%' placeholder into the URL.

Understand the failure class

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/65848afefbbf1667. Report an issue: GitHub.