Repository navigation
fix(knowledge): keep long non-ASCII folder names valid UTF-8 - #3056
Merged
lyingbug merged 1 commit intoSep 7, 2026
Merged
Conversation
NormalizeKnowledgeFolderPath capped a directory name with segment[:MaxKnowledgeFolderSegmentLength] (internal/types/knowledge_folder.go:51). That is a raw byte index, so a name longer than 128 bytes was cut wherever byte 128 landed. For a Chinese folder name that is inside the 43rd character, and the leading bytes of the half-cut character stay in the string. The result is an invalid UTF-8 folder_path. json.Marshal replaces the broken bytes with U+FFFD, so the path the client reads back is not the path stored in the row, and RenameKnowledgeFolder (internal/application/service/knowledge.go:611) normalizes that returned value and matches nothing. The cut now backs off to the nearest rune start. The cap stays a byte budget, so a 60-character Chinese name keeps its first 42 characters (126 bytes) instead of 128 bytes ending in half a character. ASCII names are unchanged.
7 of 17 tasks
6 of 17 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
NormalizeKnowledgeFolderPathcaps a directory name withsegment[:MaxKnowledgeFolderSegmentLength]atinternal/types/knowledge_folder.go:51. That index counts bytes, so a name longer than 128 bytes is cut wherever byte 128 happens to land. In a Chinese folder name that is inside the 43rd character, and the leading bytes of the half-cut character stay in the string, so thefolder_pathwritten toknowledgesis not valid UTF-8.The damage shows up downstream.
json.Marshalreplaces the broken bytes with U+FFFD, so the folder path the client reads back is not the one stored in the row. Send that value to a rename andRenameKnowledgeFolder(internal/application/service/knowledge.go:611) normalizes it into asourcethat no longer equals the storedfolder_path, soRenameKnowledgeFolderPathmatches nothing. The sidebar label for the folder also ends in a replacement character.The cut now backs off to the nearest rune start. The cap stays a byte budget, so the invariant the constant exists for (one segment cannot eat the whole 1024-byte path budget) is unchanged, and an ASCII name truncates at exactly the same place it did before. A 60-character Chinese name keeps its first 42 characters, 126 bytes, instead of 128 bytes ending in half a character.
Type of Change
Related Issue
No issue filed. Found while reading the folder path normalizer.
Testing
New test
TestNormalizeKnowledgeFolderPathKeepsSegmentsValidUTF8ininternal/types/knowledge_folder_test.gocovers a 60-character Chinese segment and an ASCII name with a two-byte character straddling the cap. Scoped to the changed package, as the README's Validation section suggests for a focused PR. Go 1.26.4 on macOS arm64.Restoring only
knowledge_folder.gofrommainand keeping the new test gives the failure this fixes:Checklist
git diff --check origin/main...HEADpassesgolangci-lint run --new-from-rev=origin/main ./...)docs/, Swagger annotations, etc.)Screenshots / Recordings
None. No UI change.