fix: 修复URL query 被逗号拆分导致目标页参数不完整的问题#2475
Open
dos1in wants to merge 2 commits intodidi:masterfrom
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题描述
H5 页面调用:
wx.miniProgram.navigateTo({
url: '/pages/detail?data=' + JSON.stringify(data)
})
在 RN 下会进入 web-view 的消息处理,再调用 RN 路由的 navigateTo。
RN 路由解析 URL 时走:
packages/api-proxy/src/platform/api/route/index.ios.js (line 46)
const { path, queryObj } = parseUrl(options.url, true)
noDecode=true 等于不做 decodeURIComponent,但后续仍会走 parseQuery 拆 query。
在 packages/utils/src/url.js (line 100) 原逻辑:
const queryArgs = query.split(/[,&]/g)它会同时按
&和,拆参数。之前传入的 JSON.stringify(data) 生成的 JSON 里就会包含逗号,比如:
?data={"a":1,"b":2}会被拆成:
导致目标页拿到的 query.data 在 JSON.parse(query.data) 时报错。
修复方案
当前修复方式是noDecode=true的情况下不应再把
,当 query 分隔符。另外补充了该问题场景下的相应的测试用例。