Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 修复onlaunch&onshow内参数被decode过的问题 #1883

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@
"@d11/react-native-fast-image": "^8.6.12",
"@mpxjs/api-proxy": "^2.9.0",
"@mpxjs/store": "^2.9.0",
"@react-navigation/native": "^7.0.14",
"@react-navigation/native-stack": "^7.2.0",
"@react-navigation/native": "^6.1.18",
"@react-navigation/native-stack": "^6.11.0",
"react": "*",
"react-native": "*",
"react-native-gesture-handler": "^2.19.0",
"react-native-linear-gradient": "^2.8.3",
"react-native-reanimated": "^3.15.2",
"react-native-safe-area-context": "^4.14.0",
"react-native-screens": "^4.1.0",
"react-native-screens": "^3.32.0",
"react-native-video": "^6.9.0",
"react-native-webview": "^13.10.5",
"vue": "^2.7.10",
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/platform/createApp.ios.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import transferOptions from '../core/transferOptions'
import builtInKeysMap from './patch/builtInKeysMap'
import { makeMap, spreadProp, getFocusedNavigation, hasOwn } from '@mpxjs/utils'
import { makeMap, spreadProp, getFocusedNavigation, hasOwn, encodeObjValues } from '@mpxjs/utils'
import { mergeLifecycle } from '../convertor/mergeLifecycle'
import { LIFECYCLE } from '../platform/patch/lifecycle/index'
import Mpx from '../index'
Expand Down Expand Up @@ -111,7 +111,7 @@ export default function createApp (options) {
const current = state.routes[state.index]
const options = {
path: current.name,
query: current.params,
query: encodeObjValues(current.params),
scene: 0,
shareTicket: '',
referrerInfo: {},
Expand Down Expand Up @@ -140,7 +140,7 @@ export default function createApp (options) {
const current = state.routes[state.index]
options = {
path: current.name,
query: current.params,
query: encodeObjValues(current.params),
scene: 0,
shareTicket: '',
referrerInfo: {}
Expand Down
10 changes: 2 additions & 8 deletions packages/core/src/platform/patch/getDefaultOptions.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as ReactNative from 'react-native'
import { ReactiveEffect } from '../../observer/effect'
import { watch } from '../../observer/watch'
import { reactive, set, del } from '../../observer/reactive'
import { hasOwn, isFunction, noop, isObject, isArray, getByPath, collectDataset, hump2dash, dash2hump, callWithErrorHandling, wrapMethodsWithErrorHandling } from '@mpxjs/utils'
import { hasOwn, isFunction, noop, isObject, isArray, getByPath, collectDataset, hump2dash, dash2hump, callWithErrorHandling, wrapMethodsWithErrorHandling, encodeObjValues } from '@mpxjs/utils'
import MpxProxy from '../../core/proxy'
import { BEFOREUPDATE, ONLOAD, UPDATED, ONSHOW, ONHIDE, ONRESIZE, REACTHOOKSEXEC } from '../../core/innerLifecycle'
import mergeOptions from '../../core/mergeOptions'
Expand Down Expand Up @@ -506,14 +506,8 @@ export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) {
if (!global.__mpxAppHotLaunched && global.__mpxAppOnLaunch) {
global.__mpxAppOnLaunch(props.navigation)
}
const loadParams = {}
// 此处拿到的props.route.params内属性的value被进行过了一次decode, 不符合预期,此处额外进行一次encode来与微信对齐
if (isObject(props.route.params)) {
for (const key in props.route.params) {
loadParams[key] = encodeURIComponent(props.route.params[key])
}
}
proxy.callHook(ONLOAD, [loadParams])
proxy.callHook(ONLOAD, [encodeObjValues(props.route.params)])
}
proxy.mounted()
return () => {
Expand Down
17 changes: 15 additions & 2 deletions packages/utils/src/url.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isArray, type, forEach } from './base'
import { isArray, type, forEach, isObject } from './base'

function encode (val) {
return encodeURIComponent(val)
Expand All @@ -8,6 +8,18 @@ function decode (val) {
return decodeURIComponent(val)
}

function encodeObjValues (obj) {
let retObj = {}
if (isObject(obj)) {
for (const key in obj) {
retObj[key] = encodeURIComponent(obj[key])
}
} else {
retObj = obj
}
return retObj
}

function isURLSearchParams (val) {
return typeof URLSearchParams !== 'undefined' && val instanceof URLSearchParams
}
Expand Down Expand Up @@ -157,5 +169,6 @@ export {
parseUrl,
parseQuery,
parseUrlQuery,
serialize
serialize,
encodeObjValues
}
Loading