Skip to content

Commit

Permalink
fix: decode URI encoded paths before resolving
Browse files Browse the repository at this point in the history
Closes #84
  • Loading branch information
JonasKruckenberg committed May 3, 2021
1 parent 71d0ff3 commit 36636e5
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 2 deletions.
3 changes: 3 additions & 0 deletions packages/rollup/src/__tests__/__fixtures__/with space.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions packages/rollup/src/__tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,21 @@ describe('rollup-plugin-imagetools', () => {
const files = await getFiles(bundle, '**.png') as OutputAsset[]
expect(files[0].source).toMatchImageSnapshot()
})

test('import with space in identifier', async () => {
const bundle = await rollup({
plugins: [
testEntry(`
import Image from "./with space.png?w=300"
export default Image
`),
imagetools()
]
})

const files = await getFiles(bundle, '**.png') as OutputAsset[]
expect(files[0].source).toMatchImageSnapshot()
})

test('non existent file', async () => {
const p = rollup({
Expand Down
2 changes: 1 addition & 1 deletion packages/rollup/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function imagetools(userOptions: Partial<PluginOptions> = {}): Plugin {
const parameters = parseURL(src)
const imageConfigs = resolveConfigs(parameters)

const img = loadImage(src.pathname)
const img = loadImage(decodeURIComponent(src.pathname))

const outputMetadatas = []

Expand Down
3 changes: 3 additions & 0 deletions packages/vite/src/__tests__/__fixtures__/with space.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions packages/vite/src/__tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,23 @@ describe('vite-imagetools', () => {
expect(files[0].source).toMatchImageSnapshot()
})

test('import with space in identifier', async () => {
const bundle = await build({
logLevel: 'warn',
build: { write: false },
plugins: [
testEntry(`
import Image from "./with space.png?w=300"
export default Image
`),
imagetools()
]
}) as RollupOutput | RollupOutput[]

const files = getFiles(bundle, '**.png') as OutputAsset[]
expect(files[0].source).toMatchImageSnapshot()
})

test('non existent file', async () => {
const p = build({
logLevel: 'warn',
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function imagetools(userOptions: Partial<PluginOptions> = {}): Plugin {
const parameters = parseURL(src)
const imageConfigs = resolveConfigs(parameters)

const img = loadImage(src.pathname)
const img = loadImage(decodeURIComponent(src.pathname))

const outputMetadatas = []

Expand Down

0 comments on commit 36636e5

Please sign in to comment.