Skip to content

Commit

Permalink
fix: 修复Taro使用原生页面(微信小程序)时, .wxml中的src={{url}},来自data的url被异常解析的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
zhengyanan1 authored and zhengyanan18 committed Oct 16, 2024
1 parent e1aa8a8 commit 33326ee
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { isUrlRequest, urlToRequest } from 'loader-utils'

Check failure on line 1 in packages/taro-webpack5-runner/src/loaders/miniTemplateLoader.ts

View workflow job for this annotation

GitHub Actions / Testing on Node.js 18.x (ubuntu-latest)

Run autofix to sort these imports!

Check failure on line 1 in packages/taro-webpack5-runner/src/loaders/miniTemplateLoader.ts

View workflow job for this annotation

GitHub Actions / Testing on Node.js 20.x (ubuntu-latest)

Run autofix to sort these imports!

Check failure on line 1 in packages/taro-webpack5-runner/src/loaders/miniTemplateLoader.ts

View workflow job for this annotation

GitHub Actions / Testing on Node.js (macos-12)

Run autofix to sort these imports!

Check failure on line 1 in packages/taro-webpack5-runner/src/loaders/miniTemplateLoader.ts

View workflow job for this annotation

GitHub Actions / Testing on Node.js (windows-latest)

Run autofix to sort these imports!
import sax from 'sax'
import { isSpecialFormat } from '../utils/index'

export default function miniTemplateLoader (source) {
this.cacheable && this.cacheable()
Expand All @@ -20,6 +21,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 33326ee

Please sign in to comment.