Skip to content
Myr

fix(utils/url): calculate ends with slash on every iteration (#3910)

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

authored by Lucas · committed by GitHub · parent 6ceb1ab · Browse files · 2 files+6 added−2 removed
This commit

State

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

Diff stats

2 files+6 added−2 removed

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

2 files+6 added−2 removed

modified:src/utils/url.test.ts+2 added
150 unmodified lines
151 expect(mergePath('/book/', '/hey/')).toBe('/book/hey/')152 expect(mergePath('/book', 'hey', 'say')).toBe('/book/hey/say')153 expect(mergePath('/book', '/hey/', '/say/')).toBe('/book/hey/say/')154 expect(mergePath('/book', '/hey/', '/say/', '/')).toBe('/book/hey/say/')155 expect(mergePath('/book', '/hey', '/say', '/')).toBe('/book/hey/say')156 expect(mergePath('/', '/book', '/hey', '/say', '/')).toBe('/book/hey/say')157158 expect(mergePath('book', '/')).toBe('/book')159 expect(mergePath('book/', '/')).toBe('/book/')160 expect(mergePath('book', '/hey')).toBe('/book/hey')
138 unmodified lines
modified:src/utils/url.ts+4 added-2 removed
139 unmodified lines
140 let p: string = ''141 let endsWithSlash = false142143 for (let path of paths) {144 // calculate endsWithSlash at the start of each iteration145 endsWithSlash = p.at(-1) === '/'146147 /* ['/hey/','/say'] => ['/hey', '/say'] */145 if (p.at(-1) === '/') {148 if (endsWithSlash) {149 p = p.slice(0, -1)147 endsWithSlash = true150 }151152 /* ['/hey','say'] => ['/hey', '/say'] */153 if (path[0] !== '/') {
165 unmodified lines