Skip to content

Commit

Permalink
fixed bug with urlAssembly of query
Browse files Browse the repository at this point in the history
  • Loading branch information
stackoverfloweth committed Dec 5, 2024
1 parent e90d358 commit 34086cc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/services/urlAssembly.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,24 @@ describe('query params', () => {

expect(url).toBe('/?simple=ABC')
})

test('given route with multiple empty and optional query params, removes both from url', () => {
const parent = createRoute({
query: 'search=[?search]'
})

const route = createRoute({
parent,
name: 'simple',
path: '/',
query: query('sort=[?sort]', {sort: Boolean}),
component,
})

const url = assembleUrl(route)

expect(url).toBe('/')
})
})

describe('static query', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/services/urlAssembly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function assembleQueryParamValues(query: Query, paramValues: Record<string, unkn
return search
}

for (const [key, value] of search.entries()) {
for (const [key, value] of Array.from(search.entries())) {
const paramName = getParamName(value)
const isNotParam = !paramName

Expand Down

0 comments on commit 34086cc

Please sign in to comment.