Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/parser/docx/document.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ describe('parseDocument — text extraction', () => {
const result = parseDocument(xml, emptyNumberingMap());
expect(result[0]?.text).toBe('<Insert text here>');
});

// Regression (#120): Word splits a number like "09 91 26" across runs at
// edit/rsid boundaries. A run whose text is a bare integer ("9") was coerced
// to a JS number by fast-xml-parser and dropped — corrupting "09 91 26" → "09 1 26".
it('preserves a bare-integer run split across a number (#120: numeric run drop)', () => {
const xml = makeDocXml(
`<w:p><w:r><w:t xml:space="preserve">09 </w:t></w:r>` +
`<w:r><w:t>9</w:t></w:r>` +
`<w:r><w:t xml:space="preserve">1 26</w:t></w:r></w:p>`
);
const result = parseDocument(xml, emptyNumberingMap());
expect(result[0]?.text).toBe('09 91 26');
});
});

describe('parseDocument — pPr field extraction', () => {
Expand Down
5 changes: 5 additions & 0 deletions src/parser/docx/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@ import type { DocxParagraph, NumberingMap } from './types.js';
// and angle brackets; setting false would corrupt those characters in paragraph text.
// trimValues: false preserves trailing/leading spaces in w:t text nodes — trimming would
// corrupt concatenated paragraph text across adjacent runs.
// parseTagValue: false keeps w:t text as strings (#120): fxp's default numeric coercion
// turns a bare-integer run (<w:t>9</w:t>) into the number 9, which extractRunText cannot
// read and silently drops — deleting digits from numbers Word split across runs, e.g.
// "09 91 26" stored as ["09 ", "9", "1 26"] rendered as "09 1 26".
const xmlParser = new XMLParser({
ignoreAttributes: false,
attributeNamePrefix: '@_',
textNodeName: '#text',
processEntities: true,
trimValues: false,
parseTagValue: false,
isArray: (name) => ['w:p', 'w:r', 'w:hyperlink'].includes(name),
});

Expand Down