A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/PanJiaChen/vue-element-admin/commit/a50180f6538aba51074f0152157075337e73a4fd below:

param2Obj bug when url params includes ==(#3100) · PanJiaChen/vue-element-admin@a50180f · GitHub

File tree Expand file treeCollapse file tree 2 files changed

+29

-13

lines changed

Filter options

Expand file treeCollapse file tree 2 files changed

+29

-13

lines changed Original file line number Diff line number Diff line change

@@ -162,19 +162,21 @@ export function param(json) {

162 162

* @returns {Object}

163 163

*/

164 164

export function param2Obj(url) {

165 -

const search = url.split('?')[1]

166 -

if (!search) {

167 -

return {}

168 -

}

169 -

return JSON.parse(

170 -

'{"' +

171 -

decodeURIComponent(search)

172 -

.replace(/"/g, '\\"')

173 -

.replace(/&/g, '","')

174 -

.replace(/=/g, '":"')

175 -

.replace(/\+/g, ' ') +

176 -

'"}'

177 -

)

165 +

const search = decodeURIComponent(url.split('?')[1]).replace(/\+/g, ' ')

166 +

if (!search) {

167 +

return {}

168 +

}

169 +

const obj = {}

170 +

const searchArr = search.split('&')

171 +

searchArr.forEach(v => {

172 +

const index = v.indexOf('=')

173 +

if (index !== -1) {

174 +

const name = v.substring(0, index)

175 +

const val = v.substring(index + 1, v.length)

176 +

obj[name] = val

177 +

}

178 +

})

179 +

return obj

178 180

}

179 181 180 182

/**

Original file line number Diff line number Diff line change

@@ -0,0 +1,14 @@

1 +

import { param2Obj } from '@/utils/index.js'

2 +

describe('Utils:param2Obj', () => {

3 +

const url = 'https://github.com/PanJiaChen/vue-element-admin?name=bill&age=29&sex=1&field=dGVzdA==&key=%E6%B5%8B%E8%AF%95'

4 + 5 +

it('param2Obj test', () => {

6 +

expect(param2Obj(url)).toEqual({

7 +

name: 'bill',

8 +

age: '29',

9 +

sex: '1',

10 +

field: window.btoa('test'),

11 +

key: '测试'

12 +

})

13 +

})

14 +

})

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4