Skip to content

enforce strict relative subpath validation in builders; reject absolu… - #2

Merged
prabhu merged 2 commits into
mainfrom
feature/subpath-validation
Apr 26, 2026
Merged

enforce strict relative subpath validation in builders; reject absolu…#2
prabhu merged 2 commits into
mainfrom
feature/subpath-validation

Conversation

@prabhu

@prabhu prabhu commented Apr 26, 2026

Copy link
Copy Markdown
Member

…te and Windows-style subpaths with actionable errors; document subpath validation; add OS matrix CI

…te and Windows-style subpaths with actionable errors; document subpath validation; add OS matrix CI

Signed-off-by: Prabhu Subramanian <prabhu@appthreat.com>
Copilot AI review requested due to automatic review settings April 26, 2026 12:11
…cross platforms

Signed-off-by: Prabhu Subramanian <prabhu@appthreat.com>
@prabhu
prabhu merged commit 8433f28 into main Apr 26, 2026
11 checks passed
@prabhu
prabhu deleted the feature/subpath-validation branch April 26, 2026 12:15

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR tightens subpath handling to prevent absolute/Windows-style subpaths when constructing PURLs from parts (builders/object flows), while keeping parser compatibility via canonicalization. It also documents the behavior and adds CI coverage across OSes.

Changes:

  • Enforce strict relative subpath validation in build()/Purl.from()/typed builders (reject absolute + Windows absolute forms with E_INVALID_SUBPATH).
  • Add tests covering new subpath validation and parser canonicalization behavior.
  • Document subpath rules in the README and add a GitHub Actions OS matrix job.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
index.js Adds stricter subpath validation logic rejecting absolute and Windows absolute inputs.
test/typed-builders.test.js Adds assertions that builder/object flows reject absolute and Windows absolute subpaths.
test/strict-encoding-edge-cases.test.js Adds a compatibility test ensuring parse() canonicalizes absolute-looking raw subpaths.
README.md Documents builder/object subpath validation rules and parser canonicalization behavior.
.github/workflows/ci.yml Adds an OS matrix CI job running the test suite on ubuntu/macos/windows.
package.json Bumps package version to 0.0.2.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread index.js
Comment on lines +562 to +566
if (subpath.startsWith("\\") || /^[A-Za-z]:[\\/]/.test(subpath)) {
throw createError(
"E_INVALID_SUBPATH",
'Absolute subpaths are not allowed; use a relative subpath like "a/b" instead of "/a/b"'
);

Copilot AI Apr 26, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message used for Windows absolute subpaths is the same as the POSIX case and suggests avoiding "/a/b", which is confusing when the rejected input is like "C:\docs\api" or "\\server\share". Consider tailoring the message based on which absolute form was detected (or using a more generic example that covers both), and de-duplicating the message text between the two checks so they can’t drift.

Copilot uses AI. Check for mistakes.
Comment thread .github/workflows/ci.yml
- name: Check generated type-rules freshness
run: node scripts/check-generated-type-rules.mjs

- name: Run full test suite

Copilot AI Apr 26, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This OS-matrix job runs pnpm test (i.e., node --test), which will also execute the deterministic fuzz suites with their default case counts/seeds on macOS/Windows. That can significantly increase CI time and flake risk compared to the main ubuntu job where fuzzing is controlled via explicit env vars. Consider running only the focused suites here (or setting much smaller PURL_FUZZ_* env values / skipping fuzz) to keep the matrix fast and stable while still validating OS-specific behavior.

Suggested change
- name: Run full test suite
- name: Run full test suite
env:
PURL_FUZZ_CASES: "10"
PURL_FUZZ_SEED: "1"

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants