Skip to content

Commit

Permalink
feat(runtime): url search params 容错处理 (#15717) (#15982)
Browse files Browse the repository at this point in the history
  • Loading branch information
koppthe committed Jun 25, 2024
1 parent f852d5b commit bab6f51
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions packages/taro-runtime/src/bom/URLSearchParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,18 @@ export const URLSearchParams = process.env.TARO_PLATFORM === 'web' ? env.window.
for (let pairs = query.split('&'), i = 0, length = pairs.length; i < length; i++) {
const value = pairs[i]
const index = value.indexOf('=')
if (index > -1) {
appendTo(dict, decode(value.slice(0, index)), decode(value.slice(index + 1)))
} else if (value.length) {
appendTo(dict, decode(value), '')

// 针对不规范的 url 参数做容错处理,如:word=你%好
try {
if (index > -1) {
appendTo(dict, decode(value.slice(0, index)), decode(value.slice(index + 1)))
} else if (value.length) {
appendTo(dict, decode(value), '')
}
} catch (err) {
if (process.env.NODE_ENV !== 'production') {
console.warn(`[Taro warn] URL 参数 ${value} decode 异常`)
}
}
}
} else {
Expand Down

0 comments on commit bab6f51

Please sign in to comment.