Skip to content

Runtime error: repo_name.split('/') without null check in multiple components #2911

@sykp241095

Description

@sykp241095

Bug Description

Multiple components in the codebase use repo_name.split('/') without checking if the repo_name contains a '/' character. This can cause runtime errors when repo_name is:

  • An empty string
  • A string without '/' separator
  • Malformed

Affected Files

  1. apps/web/app/ai-home-content.tsx (lines 329, 333, 347)
  2. apps/web/app/trending/ai/content.tsx (line 62)
  3. apps/web/app/analyze/(repo)/[owner]/[repo]/_sections/SimilarReposRadial.tsx (line 89)

Example

// Current code
const owner = repo.repo_name.split('/')[0] || '';
const shortName = repo.repo_name.split('/')[1] || repo.repo_name;

If repo_name is `` or somerepo (no slash):

  • split('/')[1] returns undefined
  • Fallback to repo.repo_name is not the intended behavior
  • Avatar URL becomes https://github.com/.png?size=40 (invalid)

Suggested Fix

Add proper validation before splitting:

const parts = repo.repo_name?.split('/') ?? [];
const owner = parts[0] || '';
const shortName = parts[1] || repo.repo_name;

Or use a helper function:

function parseRepoName(repoName: string): { owner: string; repo: string } {
  const parts = repoName?.split('/') ?? [];
  if (parts.length >= 2) {
    return { owner: parts[0], repo: parts[1] };
  }
  return { owner: '', repo: repoName };
}

Impact

  • Broken avatar images for repos with malformed names
  • Incorrect display names in treemap and other visualizations
  • Potential console errors in production

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions