Skip to content

Commit

Permalink
Merge pull request #16637 from NervJS/bugfix-inner_issue-C2024090427890
Browse files Browse the repository at this point in the history
fix: 修复Taro使用原生页面(微信小程序)时, .wxml中的src={{url}},来自data的url被异常解析的bug
  • Loading branch information
zhengyanan1 authored Oct 16, 2024
2 parents e1aa8a8 + 6dd47cb commit 76ba530
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { isUrlRequest, urlToRequest } from 'loader-utils'
import sax from 'sax'

import { isSpecialFormat } from '../utils/index'

export default function miniTemplateLoader (source) {
this.cacheable && this.cacheable()
/**
Expand All @@ -20,6 +22,8 @@ export default function miniTemplateLoader (source) {

parser.onattribute = ({ name, value }) => {
if (value && (name === 'src' || name === 'from') && isUrlRequest(value)) {
if (isSpecialFormat(name, value)) return

const request = urlToRequest(value)
requests.add(request)
}
Expand Down
9 changes: 9 additions & 0 deletions packages/taro-webpack5-runner/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,12 @@ export const formatOpenHost = (host?: string) => {
export function parsePublicPath (publicPath = '/') {
return ['', 'auto'].includes(publicPath) ? publicPath : addTrailingSlash(publicPath)
}

export function isSpecialFormat(key: string, value: string) {
if (key === 'src' && /{{\s*\w+\s*}}/.test(value)) {
// in .wxml, the value url in <web-view src="{{url}}"/> should not be requested, it is a state value in page data
return true
}

return false
}

0 comments on commit 76ba530

Please sign in to comment.