Skip to content

core-xform: Tolerate a missing cp: namespace for the coreProperties element #564

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

papandreou
Copy link
Contributor

I ran into a weird spreadsheet that claims it was generated by Apache POI. It is missing the cp: namespace for the <cp:coreProperties> element:

<?xml version="1.0" encoding="UTF-8"?>

<coreProperties xmlns="http://schemas.openxmlformats.org/package/2006/metadata/core-properties" xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <dcterms:created xsi:type="dcterms:W3CDTF">2018-05-08T14:56:50Z</dcterms:created>
  <dc:creator>Apache POI</dc:creator>
</coreProperties>

which makes exceljs die with:

Error: Unexpected xml node in parseClose: coreProperties
    at module.exports.parseClose (/Users/andreaslind/work/exceljs/lib/xlsx/xform/core/core-xform.js:126:15)
    at SAXStream.<anonymous> (/Users/andreaslind/work/exceljs/lib/xlsx/xform/base-xform.js:87:21)
    at SAXStream.emit (events.js:160:13)
    at SAXParser.me._parser.(anonymous function) [as onclosetag] (/Users/andreaslind/work/exceljs/node_modules/sax/lib/sax.js:258:17)
    at emit (/Users/andreaslind/work/exceljs/node_modules/sax/lib/sax.js:624:35)
    at emitNode (/Users/andreaslind/work/exceljs/node_modules/sax/lib/sax.js:629:5)
    at closeTag (/Users/andreaslind/work/exceljs/node_modules/sax/lib/sax.js:889:7)
    at SAXParser.write (/Users/andreaslind/work/exceljs/node_modules/sax/lib/sax.js:1436:13)
    at SAXStream.write (/Users/andreaslind/work/exceljs/node_modules/sax/lib/sax.js:239:18)
    at /Users/andreaslind/work/exceljs/lib/utils/stream-buf.js:195:14

The enclosed fix tolerates the missing namespace so the metadata is parsed.

@papandreou
Copy link
Contributor Author

Sorry, the error and stack trace isn’t the right one, it was initially complaining in parseOpen.

@papandreou
Copy link
Contributor Author

The correct stack trace was:

Error: Unexpected xml node in parseOpen: {"name":"coreProperties","attributes":{"xmlns":"http://schemas.openxmlformats.org/package/2006/metadata/core-properties","xmlns:cp":"http://schemas.openxmlformats.org/package/2006/metadata/core-properties","xmlns:dc":"http://purl.org/dc/elements/1.1/","xmlns:dcterms":"http://purl.org/dc/terms/","xmlns:xsi":"http://www.w3.org/2001/XMLSchema-instance"},"isSelfClosing":false}
  File "/app/node_modules/exceljs/dist/es5/xlsx/xform/core/core-xform.js", line 89, in module.exports.parseOpen
            throw new Error('Unexpected xml node in parseOpen: ' + JSON.stringify(node));
  File "/app/node_modules/exceljs/dist/es5/xlsx/xform/base-xform.js", line 69, in SAXStream.<anonymous>
              self.parseOpen(node);
  File "events.js", line 180, in SAXStream.emit
  File "domain.js", line 421, in SAXStream.emit
  File "SAXParser.me._parser.(anonymous function) [as onopentag] (/app/node_modules/exceljs/node_modules/sax/lib/sax.js", line 258, in <unknown>
  File "/app/node_modules/exceljs/node_modules/sax/lib/sax.js", line 624, in emit
        parser[event] && parser[event](data)
  File "/app/node_modules/exceljs/node_modules/sax/lib/sax.js", line 629, in emitNode
        emit(parser, nodeType, data)
  File "/app/node_modules/exceljs/node_modules/sax/lib/sax.js", line 825, in openTag
        emitNode(parser, 'onopentag', parser.tag)
  File "/app/node_modules/exceljs/node_modules/sax/lib/sax.js", line 1391, in SAXParser.write
                openTag(parser)
  File "/app/node_modules/exceljs/node_modules/sax/lib/sax.js", line 239, in SAXStream.write
        this._parser.write(data.toString())
  File "/app/node_modules/exceljs/dist/es5/utils/stream-buf.js", line 196, in <unknown>
            pipe.write(chunk.toBuffer(), function () {
  File "<anonymous>", line unknown, in new Promise
  File "/app/node_modules/promish/lib/promish-class.js", line 23, in new Promish
            super(f);
  File "/app/node_modules/exceljs/dist/es5/utils/stream-buf.js", line 195, in write
          return new PromishLib.Promish(function (resolve) {
  File "<anonymous>", line unknown, in Array.map
  File "/app/node_modules/exceljs/dist/es5/utils/stream-buf.js", line 201, in module.exports._pipe
        var promises = this.pipes.map(write);
  File "/app/node_modules/exceljs/dist/es5/utils/stream-buf.js", line 265, in module.exports._flush
            this._pipe(this.buffers.shift());
  File "/app/node_modules/exceljs/dist/es5/utils/stream-buf.js", line 280, in writeComplete
            _this._flush();
  File "/app/node_modules/exceljs/dist/es5/utils/stream-buf.js", line 290, in module.exports.end
          writeComplete();
  File "/app/node_modules/exceljs/dist/es5/utils/stream-buf.js", line 340, in module.exports.pipe
          this.end();
  File "/app/node_modules/exceljs/dist/es5/xlsx/xform/base-xform.js", line 102, in module.exports.parseStream
        stream.pipe(parser);
  File "/app/node_modules/exceljs/dist/es5/xlsx/xlsx.js", line 302, in ZipReader.<anonymous>
              promise = coreXform.parseStream(entry).then(function (coreProperties) {

@guyonroche guyonroche merged commit 22f464a into exceljs:master Jun 5, 2018
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.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy