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: 查询值为数组时的分隔符问题 #301

Merged
merged 5 commits into from
May 11, 2020

Conversation

gd4Ark
Copy link
Contributor

@gd4Ark gd4Ark commented May 9, 2020

Why

因未知原因(可能是 vue-router?)会将 地址栏 url 自动 decode,此时如果存在数组值,则会在 parse 时先被按 , 分割,导致无法正常解析:

let url = `q=area~east%2Csouth,size~20,page~1,`

// 刷新时会被自动转换为:

url = `q=area~east,south,size~20,page~1,`

// queryUtil.parse() 方法会先按 ',' 进行分割,导致原本属于同一个字段的值丢失了,就无法正常解析了

url.split(',') // ["q=area~east", "south", "size~20", "page~1", ""]

How

encode 数组值时,先使用别的分隔符;
同时由于之前发送请求和构造地址栏的 url 用的是同一个方法,但现在由于两者 stringify 的方式不一样,所以增加一个 URLStringify 用于构造发送 axios 请求的参数

Test

  • 新增 URLStringify 测试用例
  • 新增数组 stringify 测试用例

@auto-add-label auto-add-label bot added the bug Something isn't working label May 9, 2020
@netlify
Copy link

netlify bot commented May 9, 2020

Deploy preview for el-data-table ready!

Built with commit ef158b7

https://deploy-preview-301--el-data-table.netlify.app

src/utils/query.js Outdated Show resolved Hide resolved
) {
return query
.split(delimiter)
.map(param => param.split(equal))
.reduce((obj, [k, v]) => {
obj[k] = JSON.parse(decodeURIComponent(v))
// 替换回逗号
const value = decodeURIComponent(v).split(arrayDelimiter)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const value = decodeURIComponent(v).split(arrayDelimiter)
const value = decodeURIComponent(v).split(arrayDelimiter).join(',')

Co-authored-by: Donald Shen <donaldshen@users.noreply.github.com>
@donaldshen donaldshen merged commit 4483c8f into FEMessage:dev May 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants