Skip to content

fix(thumb blob path): separators be wrongly modified (#3062)#3116

Merged
HFO4 merged 2 commits intocloudreve:masterfrom
YUDONGLING:fix-thumb-path-separator-20251204.1
Dec 5, 2025
Merged

fix(thumb blob path): separators be wrongly modified (#3062)#3116
HFO4 merged 2 commits intocloudreve:masterfrom
YUDONGLING:fix-thumb-path-separator-20251204.1

Conversation

@YUDONGLING
Copy link
Copy Markdown
Member

No description provided.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes an issue where path separators in thumbnail blob paths were being incorrectly modified by filepath.Dir(). The problem occurred because filepath.Dir() normalizes path separators based on the operating system (converting "/" to "" on Windows), which is undesirable when working with storage systems that require specific separator formats regardless of OS.

Key Changes:

  • Replaced filepath.Dir() with manual string manipulation to preserve original path separators
  • Uses strings.LastIndexAny() to find the last "/" or "" and extracts the directory portion manually
  • Maintains backward compatibility while preventing unwanted separator normalization

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +167 to +171
lastSlash := strings.LastIndexAny(completeBlobPath, "/\\")
if lastSlash >= 0 {
return completeBlobPath[:lastSlash] + fsSeparator
}
return fsSeparator
Copy link

Copilot AI Dec 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ReplaceMagicVar function, including the new {blob_path} logic, lacks test coverage. Given that this function handles multiple magic variables and the complexity of path handling across different operating systems, comprehensive tests should be added to verify:

  1. The {blob_path} behavior with various path formats (e.g., "a/b/c.txt", "/c.txt", "c.txt", "a\b\c.txt")
  2. That the fix correctly preserves original path separators
  3. Edge cases like paths with mixed separators

Other similar functions in this file (RandStringRunes, ContainsUint, etc.) have test coverage in common_test.go.

Copilot uses AI. Check for mistakes.
@HFO4 HFO4 merged commit 05c68b4 into cloudreve:master Dec 5, 2025
2 checks passed
@HFO4
Copy link
Copy Markdown
Member

HFO4 commented Dec 5, 2025

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants