PDF upload fix (#23473)
Sometimes uploading PDF files resulted in "Non-whitespace before first tag." error, updating parsing library fixes the error <!-- This is an auto-generated description by cubic. --> <a href="https://cubic.dev/pr/twentyhq/twenty/pull/23473?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="Review in cubic" src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a> <!-- End of auto-generated description by cubic. -->
This commit is contained in:
@@ -37,7 +37,7 @@
|
||||
"@e2b/code-interpreter": "^2.6.0",
|
||||
"@envelop/core": "4.0.3",
|
||||
"@faker-js/faker": "9.8.0",
|
||||
"@file-type/pdf": "^0.2.0",
|
||||
"@file-type/pdf": "^0.3.0",
|
||||
"@graphql-tools/schema": "10.0.4",
|
||||
"@graphql-tools/utils": "9.2.1",
|
||||
"@graphql-yoga/nestjs": "2.1.0",
|
||||
|
||||
+25
@@ -8,6 +8,22 @@ const pdfBuffer = Buffer.from('%PDF-1.4\n', 'utf-8');
|
||||
const textBuffer = Buffer.from('Hello, world!', 'utf-8');
|
||||
const zipBuffer = Buffer.from([0x50, 0x4b, 0x03, 0x04]);
|
||||
|
||||
const pdfWithIndirectLengthXmpBuffer = Buffer.from(
|
||||
`%PDF-1.4
|
||||
1 0 obj
|
||||
<< /Type /Metadata /Subtype /XML /Length 5 0 R >>
|
||||
stream
|
||||
this is not valid xml, just padding so the (wrongly parsed) length is plausible
|
||||
endstream
|
||||
endobj
|
||||
5 0 obj
|
||||
250
|
||||
endobj
|
||||
%%EOF
|
||||
`,
|
||||
'utf-8',
|
||||
);
|
||||
|
||||
describe('extractFileInfoOrThrow', () => {
|
||||
it.each([
|
||||
{
|
||||
@@ -105,6 +121,15 @@ describe('extractFileInfoOrThrow', () => {
|
||||
},
|
||||
);
|
||||
|
||||
it('should detect PDF when an XMP metadata stream has an indirect /Length reference', async () => {
|
||||
const result = await extractFileInfoOrThrow({
|
||||
file: pdfWithIndirectLengthXmpBuffer,
|
||||
filename: 'document.pdf',
|
||||
});
|
||||
|
||||
expect(result).toEqual({ mimeType: 'application/pdf', ext: 'pdf' });
|
||||
});
|
||||
|
||||
describe('TWENTY_MIME_POLICY (Twenty deviates from IANA)', () => {
|
||||
it.each([
|
||||
{ filename: 'src/index.ts', expectedMime: 'application/typescript' },
|
||||
|
||||
Reference in New Issue
Block a user