Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/new-olives-wait.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@react-pdf/image": patch
---

Fix resolving images with special characters like space in filename
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ jobs:
strategy:
matrix:
# We aim to test all maintained LTS versions of Node.js as well as the latest stable version
node_version: [18, 20, 21]
node_version: [18, 20, 22, 24]
react_version: [16, 17, 18]

steps:
Expand Down Expand Up @@ -111,12 +111,12 @@ jobs:
run: REACT_VERSION=${{ matrix.react_version }} yarn test

e2e-node:
name: Run E2E tests (Node.js ${{ matrix.node_version }}; ${{ matrix.cjs_or_esm == 'cjs' ? 'CJS' : 'ESM' }})
name: Run E2E tests (Node.js ${{ matrix.node_version }}; ${{ matrix.cjs_or_esm }})
runs-on: ubuntu-latest
strategy:
matrix:
cjs_or_esm: [cjs, esm]
node_version: [18, 20, 21]
node_version: [18, 20, 22, 24]

steps:
- name: Checkout
Expand Down
2 changes: 1 addition & 1 deletion packages/image/src/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const getAbsoluteLocalPath = (src: string) => {
path: pathname,
} = url.parse(src);

const absolutePath = pathname ? path.resolve(pathname) : undefined;
const absolutePath = pathname ? path.resolve(src) : undefined;

if ((protocol && protocol !== 'file:') || auth || host || port || hostname) {
return undefined;
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packages/image/tests/assets/test with spaces.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 41 additions & 0 deletions packages/image/tests/resolve.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,27 @@ describe('image resolveImage', () => {
expect(image?.height).toBeGreaterThan(0);
});

test('Should render a local image from absolute path', async () => {
const absolutePath = path.join(__dirname, './assets/test.jpg');
const image = await resolveImage({ uri: absolutePath });

expect(image?.data).toBeTruthy();
expect(image?.width).toBeGreaterThan(0);
expect(image?.height).toBeGreaterThan(0);
});


test('Should render a local image from relative path', async () => {
const image = await resolveImage({
uri: 'packages/layout/tests/assets/test.jpg',
});

expect(image?.data).toBeTruthy();
expect(image?.width).toBeGreaterThan(0);
expect(image?.height).toBeGreaterThan(0);
});


test('Should render a local image from src object', async () => {
const image = await resolveImage({
uri: './packages/layout/tests/assets/test.jpg',
Expand All @@ -102,6 +123,26 @@ describe('image resolveImage', () => {
expect(image?.height).toBeGreaterThan(0);
});

test('Should render a local image with spaces in filename', async () => {
const image = await resolveImage({
uri: './packages/image/tests/assets/test with spaces.jpg',
});

expect(image?.data).toBeTruthy();
expect(image?.width).toBeGreaterThan(0);
expect(image?.height).toBeGreaterThan(0);
});

test('Should render a local image with special characters in filename', async () => {
const image = await resolveImage({
uri: './packages/image/tests/assets/special_ _%20_@&é"\'(§è!çà)-^$ù`,;:=?.+%£¨*<>.jpg',
});

expect(image?.data).toBeTruthy();
expect(image?.width).toBeGreaterThan(0);
expect(image?.height).toBeGreaterThan(0);
});

test('Should render a local image from data', async () => {
const image = await resolveImage({ data: localJPGImage, format: 'jpg' });

Expand Down