Skip to content

Commit 3e2a7a2

Browse files
authored
fix(export): preserve unicode characters in workflow filenames (#4120)
Previously, Non-ASCII characters (like Korean) in workflow names were replaced by dashes during export because of a restrictive regex. This update uses a Unicode-aware regex to allow letters and numbers from any language while still sanitizing unsafe filesystem characters. fixes #4119 Signed-off-by: JaeHyung Jang <jaehyung.jang@navercorp.com>
1 parent 49a1495 commit 3e2a7a2

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* @vitest-environment node
3+
*/
4+
import { describe, expect, it } from 'vitest'
5+
import { sanitizePathSegment } from '@/lib/workflows/operations/import-export'
6+
7+
describe('sanitizePathSegment', () => {
8+
it('should preserve ASCII alphanumeric characters', () => {
9+
expect(sanitizePathSegment('workflow-123_abc')).toBe('workflow-123_abc')
10+
})
11+
12+
it('should replace spaces with dashes', () => {
13+
expect(sanitizePathSegment('my workflow')).toBe('my-workflow')
14+
})
15+
16+
it('should replace special characters with dashes', () => {
17+
expect(sanitizePathSegment('workflow!@#')).toBe('workflow-')
18+
})
19+
20+
it('should preserve Korean characters (BUG REPRODUCTION)', () => {
21+
expect(sanitizePathSegment('한글')).toBe('한글')
22+
})
23+
24+
it('should preserve other Unicode characters', () => {
25+
expect(sanitizePathSegment('日本語')).toBe('日本語')
26+
})
27+
28+
it('should remove filesystem unsafe characters', () => {
29+
expect(sanitizePathSegment('work/flow?name*')).not.toContain('/')
30+
expect(sanitizePathSegment('work/flow?name*')).not.toContain('?')
31+
expect(sanitizePathSegment('work/flow?name*')).not.toContain('*')
32+
})
33+
})

apps/sim/lib/workflows/operations/import-export.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export interface WorkspaceExportStructure {
4848
* Sanitizes a string for use as a path segment in a ZIP file.
4949
*/
5050
export function sanitizePathSegment(name: string): string {
51-
return name.replace(/[^a-z0-9-_]/gi, '-')
51+
return name.replace(/[^\p{L}\p{N}\-_]/gu, '-').replace(/-+/g, '-')
5252
}
5353

5454
/**

0 commit comments

Comments
 (0)