Skip to content

Latest commit

 

History

History
24 lines (18 loc) · 730 Bytes

File metadata and controls

24 lines (18 loc) · 730 Bytes

Inadequate code fixture: partial relative-path guard

Source: public before-state shown in Plannotator PR #1117, Apache-2.0.

Implementation

const rel = normalizeWorkspacePath(relative(repo.cwd, filePath));
if (rel && !rel.startsWith("..") && !rel.startsWith("/")) {
  return `${normalizeWorkspacePath(repo.label)}/${rel}`;
}

The code is short and readable, but this required case fails:

const rel = "L:/repos/project/src/file.ts";
expect(isRepoRelative(rel)).toBe(false);

On Windows, path.relative() can return that absolute form when the base and target are on different drives. The predicate accepts it and prefixes a repository label.