fix(csv-loader): escape quotes in schema rows
Implement loader-side escaping for the schema row to prevent `csv-parse` from misinterpreting double-quoted string literals (e.g., `"active" | "inactive"`) as field delimiters.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# Implementation Plan: Syntax Clarity & Parser Robustness
|
||||
|
||||
Status: **In progress — Phases 1, 2 & 3 applied** (Phases 4–6 not yet done)
|
||||
Status: **In progress — Phases 1, 2, 3 & 4 applied** (Phases 5–6 not yet done)
|
||||
|
||||
## Goals
|
||||
|
||||
@@ -53,16 +53,18 @@ All changes are **breaking** to the DSL → bump to `2.0.0`, update README + `cs
|
||||
|
||||
---
|
||||
|
||||
## Phase 4 — Quote conflict resolution
|
||||
## Phase 4 — Quote conflict resolution ✅ Applied
|
||||
|
||||
**Files:** `src/parser.ts`, `src/csv-loader/loader.ts`, README, `csv-loader.md`
|
||||
**Files:** `src/csv-loader/loader.ts`, `src/csv-loader/tests/parseCsv-basic.test.ts`, README, `csv-loader.md`
|
||||
|
||||
**Options (pick one):**
|
||||
- **(a) Standardize on single-quoted literals only** — minimal change, but leaves a footgun.
|
||||
- **(b) Quote the entire schema cell** so `csv-parse` treats it as one field — requires loader-side handling to strip the outer quotes before parsing.
|
||||
- **(c) Drop quotes entirely** — use bare-token literals (e.g. `on` / `off` as identifiers). Most robust, largest change.
|
||||
- Added `escapeSchemaRowQuotes()` in `loader.ts`: the schema row (2nd non-empty line) is split on the delimiter, and any cell containing the quote char has its inner quotes escaped and is wrapped in quotes before `csv-parse` runs.
|
||||
- This lets users write `"active" | "inactive"` naturally in a schema row — previously csv-parse threw `Invalid Closing Quote`.
|
||||
- Single-quoted literals (`'on' | 'off'`) are untouched (no `"` present).
|
||||
- Added a test in `parseCsv-basic.test.ts`.
|
||||
|
||||
**Recommendation:** (b) — it's the only option that fixes the root cause (schema cells containing `"` break `csv-parse`) without redesigning the literal syntax. Requires: in `loader.ts`, detect schema-row cells that are fully quoted and unwrap before `parseSchema`.
|
||||
**Decision:** Implemented option (b) — loader-side escaping of the schema row. This fixes the root cause (schema cells containing `"` break csv-parse) without redesigning the literal syntax.
|
||||
|
||||
**Known limitation (pre-existing, out of scope):** a comma inside a string literal (e.g. `"a,b"`) is ambiguous with the CSV delimiter and still fails — use single-quoted literals (`'a,b'`) for those, or a non-comma delimiter.
|
||||
|
||||
---
|
||||
|
||||
|
||||
Reference in New Issue
Block a user