fix(compiler-sfc): transformAssetUrl should ignore inline data url (#1431)
This commit is contained in:
@@ -7,7 +7,12 @@ import {
|
||||
SourceLocation,
|
||||
TransformContext
|
||||
} from '@vue/compiler-core'
|
||||
import { isRelativeUrl, parseUrl, isExternalUrl } from './templateUtils'
|
||||
import {
|
||||
isRelativeUrl,
|
||||
parseUrl,
|
||||
isExternalUrl,
|
||||
isDataUrl
|
||||
} from './templateUtils'
|
||||
import { isArray } from '@vue/shared'
|
||||
|
||||
export interface AssetURLTagConfig {
|
||||
@@ -99,6 +104,7 @@ export const transformAssetUrl: NodeTransform = (
|
||||
!assetAttrs.includes(attr.name) ||
|
||||
!attr.value ||
|
||||
isExternalUrl(attr.value.content) ||
|
||||
isDataUrl(attr.value.content) ||
|
||||
attr.value.content[0] === '#' ||
|
||||
(!options.includeAbsolute && !isRelativeUrl(attr.value.content))
|
||||
) {
|
||||
|
||||
@@ -6,7 +6,12 @@ import {
|
||||
NodeTypes,
|
||||
SimpleExpressionNode
|
||||
} from '@vue/compiler-core'
|
||||
import { isRelativeUrl, parseUrl, isExternalUrl } from './templateUtils'
|
||||
import {
|
||||
isRelativeUrl,
|
||||
parseUrl,
|
||||
isExternalUrl,
|
||||
isDataUrl
|
||||
} from './templateUtils'
|
||||
import {
|
||||
AssetURLOptions,
|
||||
defaultAssetUrlOptions
|
||||
@@ -51,6 +56,15 @@ export const transformSrcset: NodeTransform = (
|
||||
return { url, descriptor }
|
||||
})
|
||||
|
||||
// for data url need recheck url
|
||||
for (let i = 0; i < imageCandidates.length; i++) {
|
||||
if (imageCandidates[i].url.trim().startsWith('data:')) {
|
||||
imageCandidates[i + 1].url =
|
||||
imageCandidates[i].url + ',' + imageCandidates[i + 1].url
|
||||
imageCandidates.splice(i, 1)
|
||||
}
|
||||
}
|
||||
|
||||
// When srcset does not contain any relative URLs, skip transforming
|
||||
if (
|
||||
!options.includeAbsolute &&
|
||||
@@ -78,6 +92,7 @@ export const transformSrcset: NodeTransform = (
|
||||
imageCandidates.forEach(({ url, descriptor }, index) => {
|
||||
if (
|
||||
!isExternalUrl(url) &&
|
||||
!isDataUrl(url) &&
|
||||
(options.includeAbsolute || isRelativeUrl(url))
|
||||
) {
|
||||
const { path } = parseUrl(url)
|
||||
|
||||
@@ -11,6 +11,11 @@ export function isExternalUrl(url: string): boolean {
|
||||
return externalRE.test(url)
|
||||
}
|
||||
|
||||
const dataUrlRE = /^\s*data:/i
|
||||
export function isDataUrl(url: string): boolean {
|
||||
return dataUrlRE.test(url)
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses string url into URL object.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user