Skip to content

add CP 1256 - #33

Open
facue wants to merge 3 commits into
iarna:masterfrom
FIT4Software:master
Open

add CP 1256#33
facue wants to merge 3 commits into
iarna:masterfrom
FIT4Software:master

Conversation

@facue

@facue facue commented Jun 22, 2022

Copy link
Copy Markdown

No description provided.

ygjb added a commit to Oghmere/rtf-parser that referenced this pull request Aug 16, 2026
* fix: close five more open upstream issues and adopt two stalled PRs

A sweep of everything still open on iarna/rtf-parser that is a defect rather
than a feature request. Each change carries a regression test using the
reporter's own reproduction where they supplied one.

interpreter: accept both the signed and unsigned forms of \uN
  The spec writes a code unit above 32767 as a negative number; plenty of
  producers emit the unsigned value instead, and writeInt16LE threw
  ERR_OUT_OF_RANGE on those -- an uncaught crash rather than a wrong character.
  A negative value is now normalised to its unsigned counterpart and anything
  outside the UTF-16 range is skipped rather than thrown.
  Adopts upstream PR iarna#28 by @UKayeF, whose diagnosis was right; the naive
  swap to writeUInt16LE in that PR would have broken the SIGNED form instead
  (writeUInt16LE(-1) throws), so this handles both.
  Closes: iarna#28. Also fixes the emoji break reported in iarna#15:
  \u55357 \u56842 is a surrogate pair, and both halves exceed 32767.

interpreter: \fcharset238 is CP1250, and \ansicpg1256 is available
  'CP238' was never a code page and iconv has never known it, so a document
  with an east-European font threw on its first hex escape. 1256 was mapped by
  font (\fcharset178) but rejected as a document code page.
  Adopts upstream PR iarna#33 by @facue. Closes: iarna#30, iarna#33.

interpreter: decode the Symbol font instead of throwing on it
  \fcharset2 is a glyph set, not a code page -- iconv has no 'SYMBOL' encoding,
  so a Symbol font (which is how Word writes bullets) took the whole document
  down. Adds an Adobe Symbol table for the 0xA0..0xFE range where the list
  glyphs live, so \'b7 becomes a real bullet. Any charset iconv does not
  recognise now falls back to CP1252 with a debug note rather than aborting:
  one exotic font table should not cost the reader the entire file.
  Closes: iarna#15 (the reported break and the bullet case; the
  0x20..0x7E Greek half is deliberately left unmapped and documented as such).

interpreter: skip \pict payloads instead of emitting them as text
  RTF stores an image as a hex payload inside {\pict ...}. With no handler it
  was decoded as ordinary text, so a document's content gained a span of raw
  hex -- 'before 89504e470d0a...' -- corrupting text extraction and word
  counts. Marked ignorable, exactly as \stylesheet and \info already are.
  Closes: iarna#32.

deps: drop readable-stream, iconv-lite@^0.7.3
  Only Writable and Transform were used, both built into node for a decade, so
  this REMOVES the dependency rather than bumping it. Runtime dependencies go
  from two to one, and the remaining one is current (0.4.24 dated from 2018).
  Closes: iarna#37.

Not addressed here, deliberately:
  iarna#35 tables -- a real feature, not a defect, and a large one.
  iarna#34 -- a support question about callbacks, not a bug in the parser.
  iarna#29 -- superseded: this fork already emits those six control words plus
  eight more. @wwwildcat got there first and deserves the credit.

Verified: 19 tests / 44 assertions green across both suites, lint clean, and
the 315k-character manuscript still extracts to exactly its \nofchars count
(314,892) with zero replacement characters.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* docs: record the upstream issue sweep and bump to 2.1.0

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
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