Skip to content
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

Don't break when docProps/core.xml contains <cp:contentType /> #536

Merged
merged 2 commits into from
Apr 11, 2018

Conversation

papandreou
Copy link
Contributor

@papandreou papandreou commented Apr 9, 2018

I've encountered a spreadsheet that contains:

<cp:coreProperties ...>...<cp:contentType /></cp:coreProperties>

which causes exceljs to break with:

(node:4149) Error: Unexpected xml node in parseOpen: {"name":"cp:contentType","attributes":{},"isSelfClosing":true}
    at module.exports.parseOpen (/Users/andreaslind/work/exceljs/lib/xlsx/xform/core/core-xform.js:87:15)
    at SAXStream.<anonymous> (/Users/andreaslind/work/exceljs/lib/xlsx/xform/base-xform.js:67:16)
    at emitOne (events.js:116:13)
    at SAXStream.emit (events.js:211:7)
    at SAXParser.me._parser.(anonymous function) [as onopentag] (/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 openTag (/Users/andreaslind/work/exceljs/node_modules/sax/lib/sax.js:825:5)
    at SAXParser.write (/Users/andreaslind/work/exceljs/node_modules/sax/lib/sax.js:1292:13)
    at SAXStream.write (/Users/andreaslind/work/exceljs/node_modules/sax/lib/sax.js:239:18)
(node:4149) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
    at emitWarning (internal/process/promises.js:78:15)
    at emitPendingUnhandledRejections (internal/process/promises.js:95:11)
    at runMicrotasksCallback (internal/process/next_tick.js:124:9)
    at _combinedTickCallback (internal/process/next_tick.js:131:7)
    at process._tickCallback (internal/process/next_tick.js:180:9)

Unfortunately I'm not able to share the spreadsheet that this happened with, and I don't know how it was created. If it's important I can try to create a synthetic test case with this construct in it.

@@ -27,6 +27,7 @@ var CoreXform = module.exports = function() {
'cp:revision': new DateXform({tag: 'cp:revision'}),
'cp:version': new StringXform({tag: 'cp:version'}),
'cp:contentStatus': new StringXform({tag: 'cp:contentStatus'}),
'cp:contentType': new DateXform({tag: 'cp:contentType'}),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would think this should be a StringXform?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, you're right, nice catch. I had that originally, but started playing around because that enfant terrible spreadsheet still didn't parse :)

Fixed.

@papandreou papandreou force-pushed the feature/contentType branch 2 times, most recently from 1eaede2 to 3b46510 Compare April 9, 2018 18:37
@papandreou
Copy link
Contributor Author

I just learned that the Excel file in question is an export from Xero, which is a piece of accounting software.

<cp:coreProperties ...><cp:contentType /></cp:coreProperties>
@papandreou
Copy link
Contributor Author

I guess the <cp:contentType> element is something they made up, since we haven't seen it until now. Maybe a better strategy would be to ignore these weird extra metadata elements rather than throw?

@salterok
Copy link

I also see documents with <cp:contentType />. And there are many of them.
Instead of error on unknown elements better to just display warning or ignore them completely.

There is example of a such file
1519293514-KRISHNAPATNAM_LINE_UP.xlsx

@papandreou
Copy link
Contributor Author

@salterok, thanks for weighing in! I've added a regression test based on the file that you linked to.

@guyonroche guyonroche merged commit e489525 into exceljs:master Apr 11, 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.

None yet

4 participants