Skip to content

fromArchive crashes with Error: XPDY0002: context is absent, it needs to be present to use the "." operator #58

@pbuszka

Description

@pbuszka

I triaged the problem to the following summary but not sure what is the correct way to fix it.

If the document.xml contains image that has an anchor it crashes

        <w:drawing>
          <wp:anchor allowOverlap="1" behindDoc="0" distB="0" distT="0" distL="114300"

if everything stays the same and anchor is changed to inline it passes

        <w:drawing>
          <wp:inline distB="114300" distT="114300" distL="114300" distR="114300">

it comes down to this line in fromNode for Image class

const inlineNode = evaluateXPathToFirstNode(`./${QNS.wp}inline`, node);

if I change it to

const inlineNode = evaluateXPathToFirstNode(`./${QNS.wp}anchor`, node);

Brute force "solution" doesn't crash but I presume it doesn't work as intended for anchor use case

    let inlineNode
    try { 
      inlineNode = evaluateXPathToFirstNode(`./${QNS.wp}inline`, node);
    } catch (error) {
      inlineNode = evaluateXPathToFirstNode(`./${QNS.wp}anchor`, node);
    }

Below two DOCX files that reproduce the problem (anchor and inline version of the same image), document.xml is the sme except this single change.

describe('docxml visitor debug', () => {
  it('debug docx', async () => {
    const archive_inline = await fs.readFile(path.join(__dirname, '.data/debug_min_inline.docx'))
    const docx_inline = await Docx.fromArchive(archive_inline)

    // below it crashes
    const archive_anchor = await fs.readFile(path.join(__dirname, '.data/debug_min_anchor.docx'))
    const docx_anchor = await Docx.fromArchive(archive_anchor)
  })
})

debug_min_anchor.docx
debug_min_inline.docx

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions