Skip to content

fix: enforce deterministic CSV whitespace rules - #138

Merged
mehulimukherjee merged 1 commit into
ExtractPDF4J:mainfrom
lyn1dev:fix/deterministic-csv-whitespace
Nov 30, 2026
Merged

mehulimukherjee merged 1 commit into
ExtractPDF4J:mainfrom
lyn1dev:fix/deterministic-csv-whitespace

Conversation

@lyn1dev

@lyn1dev lyn1dev commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes #16 by enforcing deterministic cell whitespace normalization in CsvExporter (and therefore Table#toCSV(char), CLI, service, and batch callers):

  • Collapse runs of horizontal whitespace (\h+, including spaces, tabs, and Unicode space separators such as NBSP \u00A0) to a single ASCII space (' ').
  • Trim leading and trailing whitespace on cell edges (and horizontal spaces adjacent to embedded line breaks in multi-line cells) while preserving single internal spaces and internal line breaks.
  • Quote cells containing \n or \r explicitly instead of checking only System.lineSeparator(), ensuring embedded LF/CR cells are quoted consistently across Windows, macOS, and Linux.
  • Add unit tests and a golden CSV fixture (extractpdf4j-core/src/test/resources/csv-whitespace-golden.csv) verified across Locale.US, Locale.GERMANY, and Locale.JAPAN.

Testing & Validation

  • Unit tests added

  • Integration test added

  • Manual verification performed

  • Benchmark results included (if performance-related)

  • The 3 new tests in CsvExporterTest fail before the fix (missing whitespace normalization, unquoted \n cell on Windows) and pass after the fix (mvn -B -pl extractpdf4j-core -Dtest=CsvExporterTest,TableTest test: 11 tests run, 0 failures).

  • Full reactor verification (mvn -B verify --file pom.xml) passes across all 6 modules (extractpdf4j-core, extractpdf4j-cli, extractpdf4j-service, extractpdf4j-example-batch-folder), with 3 assumption-skipped OCR tests in com.extractpdf4j.helpers.OcrTest where the local tesseract binary is absent.

Impact

Eliminates whitespace-only diffs in generated CSV output across operating systems, locales, and JDKs without altering raw Table cell accessors or JsonExporter.

@mehulimukherjee
mehulimukherjee merged commit c6c0c92 into ExtractPDF4J:main Nov 30, 2026
3 checks passed
@mehulimukherjee

Copy link
Copy Markdown
Member

Hi @lyn1dev , Thank you for your contribution, much appreciated, if you liked working on this project, could you please STAR the repo as well for more reach? Thanks 👍

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.

Deterministic CSV whitespace rules

2 participants