-
Notifications
You must be signed in to change notification settings - Fork 20
Fix Illegal Characters #132
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
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 |
|---|---|---|
|
|
@@ -39,17 +39,26 @@ public static List<string> GetAdditionalRenderAppearancePaths() | |
|
|
||
| foreach (var p in paths) | ||
| { | ||
| string trimmedPath = p.Trim(); | ||
| string cleanedPath = p.Trim().Trim('"'); | ||
|
|
||
| // If already rooted, normalize it | ||
| if (Path.IsPathRooted(trimmedPath)) | ||
| { | ||
| absolutePaths.Add(Path.GetFullPath(trimmedPath)); | ||
| } | ||
| else | ||
| // Replace | with ; or split further if needed | ||
| cleanedPath = cleanedPath.Replace('|', ';'); | ||
|
|
||
| foreach (var subPath in cleanedPath.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries)) | ||
| { | ||
| // Combine with user profile to resolve relative path | ||
| string fullPath = Path.GetFullPath(Path.Combine(userProfile, trimmedPath)); | ||
| string trimmedPath = subPath.Trim().Trim('"'); | ||
|
|
||
| if (Path.GetInvalidPathChars().Any(c => trimmedPath.Contains(c))) | ||
| { | ||
| // Skip or log invalid path | ||
| Console.WriteLine($"Skipping invalid path: {trimmedPath}"); | ||
| continue; | ||
| } | ||
|
|
||
| string fullPath = Path.IsPathRooted(trimmedPath) | ||
| ? Path.GetFullPath(trimmedPath) | ||
| : Path.GetFullPath(Path.Combine(userProfile, trimmedPath)); | ||
|
Comment on lines
+58
to
+60
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. 🛠️ Refactor suggestion | 🟠 Major Add exception handling for Path.GetFullPath().
Wrap the path resolution in a try-catch block: - string fullPath = Path.IsPathRooted(trimmedPath)
- ? Path.GetFullPath(trimmedPath)
- : Path.GetFullPath(Path.Combine(userProfile, trimmedPath));
-
- absolutePaths.Add(fullPath);
+ try
+ {
+ string fullPath = Path.IsPathRooted(trimmedPath)
+ ? Path.GetFullPath(trimmedPath)
+ : Path.GetFullPath(Path.Combine(userProfile, trimmedPath));
+
+ absolutePaths.Add(fullPath);
+ }
+ catch (Exception ex) when (ex is ArgumentException || ex is PathTooLongException || ex is NotSupportedException)
+ {
+ // Log using appropriate Revit logging mechanism
+ // For now, skip the invalid path
+ }
🤖 Prompt for AI Agents |
||
|
|
||
| absolutePaths.Add(fullPath); | ||
| } | ||
| } | ||
|
|
||
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.
🛠️ Refactor suggestion | 🟠 Major
🧩 Analysis chain
Invalid character validation may be insufficient, and logging is inappropriate.
Two concerns:
Path.GetInvalidPathChars()only returns null and control characters (0-31), but does NOT include characters like<,>,*,?that are invalid in Windows paths. While the code handles|and", other invalid characters might slip through and causePath.GetFullPath()to throw on lines 59-60.Console.WriteLineis inappropriate for Revit plugins, as there's no console and the message will be lost. Consider using a proper logging framework or the Revit API's logging mechanisms.Verify the sufficiency of the current validation:
🏁 Script executed:
Length of output: 1455
💡 Result:
Path.GetInvalidPathChars returns a char[] clone of the internal RealInvalidPathChars array — on Windows .NET that list is:
(So: '"', '<', '>', '|', '\0', and chars 1..31). The exact set can vary by platform and file system and the method's docs say it is not guaranteed to be complete. [1][2][3]
Sources:
[1] .NET Path.cs source (RealInvalidPathChars and InvalidFileNameChars lists).
[2] Microsoft docs: Path.GetInvalidPathChars (remarks about not guaranteed complete).
[3] Discussion / examples (Stack Overflow).
Invalid character validation is incomplete, and logging is inappropriate for Revit plugins.
Two concerns:
Path.GetInvalidPathChars()returns",<,>,|, null, and control characters, but does NOT include*or?, which are also invalid in Windows paths. Characters that slip through validation could causePath.GetFullPath()on lines 59–60 to throw an exception. Currently there is no try-catch around these calls to handle failures gracefully.Console.WriteLine()is inappropriate for Revit plugins, as there's no console and messages are lost. Consider using a proper logging framework or the Revit API's logging mechanisms.