Skip to content

fix: handle CRLF line endings in DSN parser and cross-platform test paths - #531

Open
chris200450828 wants to merge 1 commit into
tscircuit:mainfrom
chris200450828:fix/crlf-and-cross-platform-test-paths
Open

chris200450828 wants to merge 1 commit into
tscircuit:mainfrom
chris200450828:fix/crlf-and-cross-platform-test-paths

Conversation

@chris200450828

Copy link
Copy Markdown

What

Two small cross-platform robustness fixes.

1. Normalize CRLF/CR line endings in parseDsnToDsnJson

Real-world DSN files exported by KiCad on Windows use CRLF line endings. Without normalization, a parse -> stringify -> parse round-trip is not idempotent (because stringifyDsnJson emits LF), so the reparsed parser block differs from the original only by \r. This makes the parser robust to CRLF input and fixes tests/dsn-pcb/stringify-dsn-json.test.ts on such files.

2. Split the test path on both / and \ in getTestDebugUtils

testPath.split("/") never splits a Windows backslash path, so on Windows .pop() returned the entire absolute path and the helper tried to mkdir a directory literally named D:\...\<test>, throwing ENOENT. Splitting on /[/\]/ fixes the debug-file helper on Windows.

Result

On Windows the suite goes from 3 failing tests to 1 (merge-dsn-session-with-conversion and stringify dsn json now pass). No changes to behavior on LF input, so no regressions on Linux/macOS CI. Diff is 6 lines.

The remaining failure (basic-via-pcb-layer-change) is an unrelated looks-same image-buffer issue and is intentionally left out of scope to keep this focused.

…aths

Two small cross-platform robustness fixes:

1. parseDsnToDsnJson now normalizes CRLF/CR line endings to LF before
   tokenizing. Real-world DSN files exported by KiCad on Windows use CRLF,
   and without normalization a parse -> stringify -> parse round-trip is not
   idempotent (stringify emits LF), which breaks the round-trip invariant.
   This fixes tests/dsn-pcb/stringify-dsn-json.test.ts on such inputs.

2. getTestDebugUtils split the test path on "/" only, so on Windows the
   backslash-separated absolute path was never split and it attempted to
   mkdir a directory literally named after the full "D:\..." path. Splitting
   on both separators fixes the test debug-file helper on Windows.

Test suite goes from 3 failing to 1 on Windows; no regressions elsewhere.
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.

1 participant