Skip to content

Commit 88db000

Browse files
author
CodingOnStar
committed
test: enhance string handling tests for escape/unescape functions
- Updated test case to clarify handling of complex strings without backslashes. - Added new test case to document behavior for strings containing existing backslashes, highlighting the non-symmetrical nature of escape/unescape functions. - Improved code readability and understanding of string manipulation scenarios.
1 parent 4b8c37c commit 88db000

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

web/app/components/datasets/create/step-two/hooks/use-document-creation.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import type {
77
CreateDocumentReq,
88
createDocumentResponse,
99
CustomFile,
10-
DataSourceType,
1110
FullDocumentDetail,
1211
ProcessRule,
1312
} from '@/models/datasets'
@@ -18,6 +17,9 @@ import { trackEvent } from '@/app/components/base/amplitude'
1817
import Toast from '@/app/components/base/toast'
1918
import { isReRankModelSelected } from '@/app/components/datasets/common/check-rerank-model'
2019
import { DataSourceProvider } from '@/models/common'
20+
import {
21+
DataSourceType,
22+
} from '@/models/datasets'
2123
import { getNotionInfo, getWebsiteInfo, useCreateDocument, useCreateFirstDocument } from '@/service/knowledge/use-create-dataset'
2224
import { useInvalidDatasetList } from '@/service/knowledge/use-dataset'
2325
import { IndexingType } from './use-indexing-config'
@@ -170,15 +172,15 @@ export const useDocumentCreation = (options: UseDocumentCreationOptions) => {
170172
} as CreateDocumentReq
171173

172174
// Add data source specific info
173-
if (dataSourceType === 'upload_file') {
175+
if (dataSourceType === DataSourceType.FILE) {
174176
params.data_source!.info_list.file_info_list = {
175177
file_ids: files.map(file => file.id || '').filter(Boolean),
176178
}
177179
}
178-
if (dataSourceType === 'notion_import')
180+
if (dataSourceType === DataSourceType.NOTION)
179181
params.data_source!.info_list.notion_info_list = getNotionInfo(notionPages, notionCredentialId)
180182

181-
if (dataSourceType === 'website_crawl') {
183+
if (dataSourceType === DataSourceType.WEB) {
182184
params.data_source!.info_list.website_info_list = getWebsiteInfo({
183185
websiteCrawlProvider,
184186
websiteCrawlJobId,

web/app/components/datasets/create/step-two/index.spec.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2174,12 +2174,24 @@ describe('Integration Scenarios', () => {
21742174
expect(unescaped).toBe(original)
21752175
})
21762176

2177-
it('should handle complex strings', () => {
2177+
it('should handle complex strings without backslashes', () => {
2178+
// This string contains control characters but no literal backslashes.
21782179
const original = 'Hello\nWorld\t!\r\n'
21792180
const escaped = escape(original)
21802181
const unescaped = unescape(escaped)
2181-
21822182
expect(unescaped).toBe(original)
21832183
})
2184+
2185+
it('should document behavior for strings with existing backslashes', () => {
2186+
// When the original string already contains backslash sequences,
2187+
// escape/unescape are not perfectly symmetric because escape()
2188+
// does not escape backslashes.
2189+
const original = 'Hello\\nWorld'
2190+
const escaped = escape(original)
2191+
const unescaped = unescape(escaped)
2192+
// The unescaped value interprets "\n" as a newline, so it differs from the original.
2193+
expect(unescaped).toBe('Hello\nWorld')
2194+
expect(unescaped).not.toBe(original)
2195+
})
21842196
})
21852197
})

0 commit comments

Comments
 (0)