fix(read): allow reading base64 files from a dataURI scheme #2763

Merged
AbdelrahmanHafez merged 3 commits from gh-2762 into master 2022-08-08 20:41:10 +00:00
AbdelrahmanHafez commented 2022-08-08 20:07:14 +00:00 (Migrated from github.com)

fixes #2762

I'm not if the modified files are source files that get compiled or those are the compiled files.
Also, can you point me to where should the test cases for those be?

it('handles base64 within data URI scheme (gh-2762), function() {
  // Arrange
  const fileInBase64 = 'TmFtZXMNCkhhZmV6DQpTYW0NCg==';
  const fileInBase64WithDataURIScheme = 'data:text/csv;base64,TmFtZXMNCkhhZmV6DQpTYW0NCg==';

  // Act
  const workBookFromRawBase64 = XLSX.read(fileInBase64, { type: 'base64' });
  const workBookFromBase64WithinDataURI = XLSX.read(fileInBase64WithDataURIScheme, { type: 'base64' });

  // Assert
  assert.deepStrictEqual(workBookFromRawBase64, workBookFromBase64WithinDataURI);
});
fixes #2762 I'm not if the modified files are source files that get compiled or those are the compiled files. Also, can you point me to where should the test cases for those be? ```js it('handles base64 within data URI scheme (gh-2762), function() { // Arrange const fileInBase64 = 'TmFtZXMNCkhhZmV6DQpTYW0NCg=='; const fileInBase64WithDataURIScheme = 'data:text/csv;base64,TmFtZXMNCkhhZmV6DQpTYW0NCg=='; // Act const workBookFromRawBase64 = XLSX.read(fileInBase64, { type: 'base64' }); const workBookFromBase64WithinDataURI = XLSX.read(fileInBase64WithDataURIScheme, { type: 'base64' }); // Assert assert.deepStrictEqual(workBookFromRawBase64, workBookFromBase64WithinDataURI); }); ```
SheetJSDev commented 2022-08-08 20:23:17 +00:00 (Migrated from github.com)

The test should be added between line 690 and 691 in test.js: https://github.com/SheetJS/sheetjs/blob/master/test.js#L690-L691 (just after the "should read base64 strings" test)

The media type is optional and the comma need not be escaped. Try /^data:([^\/]+\/[^\/]+)?;base64,/

Include a test with a string like

  var fileInBase64WithDataURISchemeNoMediaType = 'data:;base64,TmFtZXMNCkhhZmV6DQpTYW0NCg==';

The test snippet should use avoid const and any other ES6+ features.

The test should be added between line 690 and 691 in `test.js`: https://github.com/SheetJS/sheetjs/blob/master/test.js#L690-L691 (just after the "should read base64 strings" test) The media type is optional and the comma need not be escaped. Try `/^data:([^\/]+\/[^\/]+)?;base64,/` Include a test with a string like ```js var fileInBase64WithDataURISchemeNoMediaType = 'data:;base64,TmFtZXMNCkhhZmV6DQpTYW0NCg=='; ``` The test snippet should use avoid const and any other ES6+ features.
AbdelrahmanHafez commented 2022-08-08 20:36:42 +00:00 (Migrated from github.com)

@SheetJSDev
Thanks a lot for the detailed comment, I've pushed the necessary changes.

@SheetJSDev Thanks a lot for the detailed comment, I've pushed the necessary changes.
Sign in to join this conversation.
No description provided.