-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix invalid path for windows dialogs #4019
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,11 @@ | |
|
||
package cfd | ||
|
||
import "fmt" | ||
import ( | ||
"fmt" | ||
"os" | ||
"reflect" | ||
) | ||
|
||
type FileFilter struct { | ||
// The display name of the filter (That is shown to the user) | ||
|
@@ -11,6 +15,9 @@ type FileFilter struct { | |
Pattern string | ||
} | ||
|
||
// Never obfuscate the FileFilter type. | ||
var _ = reflect.TypeOf(FileFilter{}) | ||
|
||
type DialogConfig struct { | ||
// The title of the dialog | ||
Title string | ||
|
@@ -69,13 +76,21 @@ func (config *DialogConfig) apply(dialog Dialog) (err error) { | |
} | ||
|
||
if config.Folder != "" { | ||
_, err = os.Stat(config.Folder) | ||
if err != nil { | ||
return | ||
} | ||
Comment on lines
+79
to
+82
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Path validation might be too strict for network paths. The current implementation using Consider using a more flexible path validation approach: - _, err = os.Stat(config.Folder)
- if err != nil {
- return
- }
+ if !isValidPath(config.Folder) {
+ return fmt.Errorf("invalid folder path: %s", config.Folder)
+ } Add this helper function: func isValidPath(path string) bool {
// Basic path validation
if path == "" {
return false
}
// Check if it's a Windows UNC path
if strings.HasPrefix(path, "\\\\") {
return true
}
// For local paths, check if they exist
_, err := os.Stat(path)
return err == nil
} Also applies to: 90-93 |
||
err = dialog.SetFolder(config.Folder) | ||
if err != nil { | ||
return | ||
} | ||
} | ||
|
||
if config.DefaultFolder != "" { | ||
_, err = os.Stat(config.DefaultFolder) | ||
if err != nil { | ||
return | ||
} | ||
err = dialog.SetDefaultFolder(config.DefaultFolder) | ||
if err != nil { | ||
return | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Invalid Go version specified
The specified Go version '1.23' is not yet released and may not be available. This could cause the workflow to fail.
Use a currently available Go version:
📝 Committable suggestion