Skip to content
Myr

fix(url): strip trailing question mark correctly for optional params with regex quantifiers (#5209)

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

* fix(url): strip trailing question mark correctly for optional params with regex quantifiers * fix(url): refine optional parameter detection to check trailing question mark

authored by Nanasi · committed by GitHub · parent 26de731 · Browse files · 2 files+3 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+3 added−2 removed

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

2 files+3 added−2 removed

modified:src/utils/url.test.ts+1 added
251 unmodified lines
252 expect(checkOptionalParameter('/api/:version/animal/:type?')).toEqual([253 '/api/:version/animal',254 '/api/:version/animal/:type',255 ])256 expect(checkOptionalParameter('/api/:id{[0-9]?}?')).toEqual(['/api', '/api/:id{[0-9]?}'])257 })258 })259260 describe('getQueryParam', () => {
113 unmodified lines
modified:src/utils/url.ts+2 added-2 removed
185 unmodified lines
186 segments.forEach((segment) => {187 if (segment !== '' && !/\:/.test(segment)) {188 basePath += '/' + segment189 } else if (/\:/.test(segment)) {190 if (/\?/.test(segment)) {190 if (segment.charCodeAt(segment.length - 1) === 63) {191 if (results.length === 0 && basePath === '') {192 results.push('/')193 } else {194 results.push(basePath)195 }196 const optionalSegment = segment.replace('?', '')196 const optionalSegment = segment.slice(0, -1)197 basePath += '/' + optionalSegment198 results.push(basePath)199 } else {200 basePath += '/' + segment
119 unmodified lines