Skip to content

Commit

Permalink
fix(asset): use stricter asset url marker and regex
Browse files Browse the repository at this point in the history
fix #1602
  • Loading branch information
yyx990803 committed Jan 20, 2021
1 parent 940d483 commit e6c8478
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions packages/vite/src/node/plugins/asset.ts
Expand Up @@ -9,11 +9,11 @@ import { FS_PREFIX } from '../constants'
import { PluginContext } from 'rollup'
import MagicString from 'magic-string'

export const assetUrlRE = /__VITE_ASSET__([a-z\d]+)(?:__(.*)__)?/g
export const assetUrlRE = /__VITE_ASSET__([a-z\d]{8})__(?:(.*?)__)?/g

// urls in JS must be quoted as strings, so when replacing them we need
// a different regex
const assetUrlQuotedRE = /"__VITE_ASSET__([a-z\d]+)(?:__(.*)__)?"/g
const assetUrlQuotedRE = /"__VITE_ASSET__([a-z\d]{8})__(?:(.*?)__)?"/g

/**
* Also supports loading plain strings with import text from './foo.txt?raw'
Expand Down Expand Up @@ -183,7 +183,7 @@ async function fileToBuiltUrl(
type: 'asset',
source: content
})
url = `__VITE_ASSET__${fileId}${postfix ? `__${postfix}__` : ``}`
url = `__VITE_ASSET__${fileId}__${postfix ? `${postfix}__` : ``}`
}

cache.set(id, url)
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugins/worker.ts
Expand Up @@ -61,7 +61,7 @@ export function webWorkerPlugin(config: ResolvedConfig): Plugin {
url = `__VITE_ASSET__${this.emitFile({
type: 'chunk',
id: cleanUrl(id)
})}`
})}__`
}
}

Expand Down

0 comments on commit e6c8478

Please sign in to comment.