mirror of
https://github.com/langgenius/dify.git
synced 2026-02-24 09:55:09 +00:00
fix
This commit is contained in:
@@ -235,7 +235,7 @@ describe('useDocumentListQueryState', () => {
|
||||
|
||||
await waitFor(() => expect(onUrlUpdate).toHaveBeenCalled())
|
||||
const update = onUrlUpdate.mock.calls[onUrlUpdate.mock.calls.length - 1][0]
|
||||
expect(update.searchParams.get('keyword')).toBe('test query')
|
||||
expect(update.searchParams.get('keyword')).toBe(encodeURIComponent('test query'))
|
||||
})
|
||||
|
||||
it('should remove keyword from URL when keyword is empty', async () => {
|
||||
@@ -250,6 +250,32 @@ describe('useDocumentListQueryState', () => {
|
||||
expect(update.searchParams.has('keyword')).toBe(false)
|
||||
})
|
||||
|
||||
it('should remove keyword from URL when keyword contains only whitespace', async () => {
|
||||
const { result, onUrlUpdate } = renderWithAdapter('?keyword=existing')
|
||||
|
||||
act(() => {
|
||||
result.current.updateQuery({ keyword: ' ' })
|
||||
})
|
||||
|
||||
await waitFor(() => expect(onUrlUpdate).toHaveBeenCalled())
|
||||
const update = onUrlUpdate.mock.calls[onUrlUpdate.mock.calls.length - 1][0]
|
||||
expect(update.searchParams.has('keyword')).toBe(false)
|
||||
expect(result.current.query.keyword).toBe('')
|
||||
})
|
||||
|
||||
it('should preserve literal percent-encoded-like keyword values', async () => {
|
||||
const { result, onUrlUpdate } = renderWithAdapter()
|
||||
|
||||
act(() => {
|
||||
result.current.updateQuery({ keyword: '%2F' })
|
||||
})
|
||||
|
||||
await waitFor(() => expect(onUrlUpdate).toHaveBeenCalled())
|
||||
const update = onUrlUpdate.mock.calls[onUrlUpdate.mock.calls.length - 1][0]
|
||||
expect(update.searchParams.get('keyword')).toBe(encodeURIComponent('%2F'))
|
||||
expect(result.current.query.keyword).toBe('%2F')
|
||||
})
|
||||
|
||||
it('should keep decoded keyword state when updating query from legacy URL', async () => {
|
||||
const { result, onUrlUpdate } = renderWithAdapter('?keyword=test%2520query')
|
||||
|
||||
|
||||
@@ -66,7 +66,8 @@ const parseAsKeyword = createParser<string>({
|
||||
return value
|
||||
}
|
||||
},
|
||||
serialize: value => value,
|
||||
// Keep parse/serialize symmetric while preserving legacy URL behavior.
|
||||
serialize: value => encodeURIComponent(value),
|
||||
}).withDefault('')
|
||||
|
||||
export const documentListParsers = {
|
||||
@@ -92,6 +93,8 @@ function useDocumentListQueryState() {
|
||||
patch.status = sanitizeStatusValue(patch.status)
|
||||
if ('sort' in patch)
|
||||
patch.sort = sanitizeSortValue(patch.sort)
|
||||
if ('keyword' in patch && typeof patch.keyword === 'string' && patch.keyword.trim() === '')
|
||||
patch.keyword = ''
|
||||
setQuery(patch)
|
||||
}, [setQuery])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user