Skip to content

Fix Windows path separator handling - #224

Open
hoklims wants to merge 2 commits into
sourcegraph:scipfrom
hoklims:agent/fix-windows-path-separator
Open

hoklims wants to merge 2 commits into
sourcegraph:scipfrom
hoklims:agent/fix-windows-path-separator

Conversation

@hoklims

@hoklims hoklims commented Aug 16, 2026

Copy link
Copy Markdown

What changed

  • replace the platform-derived regular expression with a separator expression that safely handles both \ and /
  • add a regression test covering Windows and POSIX paths

Why

On Windows, path.sep is \. Passing it directly to new RegExp() creates an invalid regular expression and crashes scip-python during module initialization. This addresses #210.

Accepting both separators also keeps package resolution robust when Python metadata contains mixed path styles.

Validation

  • npm test -- --runInBand — 2 suites, 8 tests passed
  • npm run check:prettier — passed
  • npm run build-agent — passed
  • native Windows indexing smoke — generated a SCIP index containing all 8 expected Python documents
@hoklims
hoklims marked this pull request as ready for review August 16, 2026 13:45
Copilot AI lite review requested due to automatic review settings August 16, 2026 13:45

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

Fixes a Windows startup crash in pyright-scip by removing the platform-derived RegExp(path.sep) (which is invalid on Windows) and replacing it with a safe separator-matching regex that works across both Windows (\) and POSIX (/) path styles.

Changes:

  • Replace new RegExp(path.sep, 'g') with a safe cross-platform separator regex (/[\\/]/g).
  • Add a regression test ensuring module resolution works with both Windows-style and POSIX-style separators in package file paths.

Reviewed changes

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

File Description
packages/pyright-scip/src/virtualenv/PythonEnvironment.ts Uses a safe, cross-platform separator regex to avoid Windows RegExp initialization crashes and handle mixed path styles.
packages/pyright-scip/src/virtualenv/PythonEnvironment.test.ts Adds coverage to confirm module resolution works for both \ and / separators.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@stacknoise

stacknoise commented Nov 17, 2026 •

Copy link
Copy Markdown

I can confirm the startup crash on Windows (SyntaxError: Invalid regular expression: //g: \ at end of pattern).

It happens with every 0.6.x release (0.6.6–0.6.8) on Windows 11 with Node 26, so scip-python can’t be used on Windows at all right now.
Would it be possible to merge this and cut a release?

Happy to help test. Thanks!

@bobcat88

Copy link
Copy Markdown

Tested this change on Windows, in case it helps the review.

Setup: Windows 11, Node.js 26.13.1, @sourcegraph/scip-python@0.6.8 from npm. Small project: pyproject.toml, plus a package pkg/ with math.py defining total() and report.py calling it.

  • Without this PR: scip-python index . --project-name pyfix --output index.scip exits at startup with SyntaxError: Invalid regular expression: /\/g: \ at end of pattern (PythonEnvironment.ts:4), as described in Windows: scip-python crashes on startup due to unescaped path.sep in RegExp #210.
  • With the same one-line change applied to the published dist/scip-python.js (new RegExp(o.sep,"g") → /[\/]/g): indexing succeeds in about 1.5 s. Both definitions and the cross-file reference to total are emitted.

One more Windows issue, separate from this PR: the emitted Document.relative_path values use backslashes (pkg\math.py, pkg\report.py). scip.proto requires / as the separator, "including on Windows" (rule 4 of relative_path). Consumers that follow the spec will see different paths for the same file on Windows and POSIX. Happy to open a separate issue if that's useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

5 participants