Skip to content
Myr

fix(utils/url): make _getQueryParam search behind question mark (#4507)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* fix(utils/url): make _getQueryParam search behind question mark * chore(utils/url): apply suggestions from review Co-authored-by: Taku Amano <taku@taaas.jp> ---------

authored by tuzi3040 · committed by GitHub · parent d3479a3 · Browse files · 2 files+7 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Co-authored-by: Taku Amano <taku@taaas.jp>

Diff stats

2 files+7 added−2 removed

  • tests:+2 added−0 removed
  • other:+5 added−2 removed

2 files+7 added−2 removed

modified:src/utils/url.test.ts+2 added
246 unmodified lines
247 })248 expect(getQueryParam('http://example.com/?pretty', 'pretty')).toBe('')249 expect(getQueryParam('http://example.com/?pretty', 'prtt')).toBe(undefined)250 expect(getQueryParam('http://example.com/?name=sam&name=tom', 'name')).toBe('sam')251 expect(getQueryParam('http://example.com/&name=sam?name=tom', 'name')).toBe('tom')252 expect(getQueryParam('http://example.com/&name=sam', 'name')).toBe(undefined)253 expect(getQueryParam('http://example.com/?name=sam&name=tom')).toEqual({254 name: 'sam',255 })256 searchParams = new URLSearchParams('?name=sam=tom')
61 unmodified lines
modified:src/utils/url.ts+5 added-2 removed
215 unmodified lines
216217 if (!multiple && key && !/[%+]/.test(key)) {218 // optimized for unencoded key219220 let keyIndex = url.indexOf(`?${key}`, 8)220 let keyIndex = url.indexOf('?', 8)221 if (keyIndex === -1) {222 keyIndex = url.indexOf(`&${key}`, 8)222 return undefined223 }224 if (!url.startsWith(key, keyIndex + 1)) {225 keyIndex = url.indexOf(`&${key}`, keyIndex + 1)226 }227 while (keyIndex !== -1) {228 const trailingKeyCode = url.charCodeAt(keyIndex + key.length + 1)229 if (trailingKeyCode === 61) {230 const valueIndex = keyIndex + key.length + 2
80 unmodified lines