Skip to content

Conversation

@vnoves
Copy link
Member

@vnoves vnoves commented Nov 6, 2025

Summary by CodeRabbit

  • Style

    • Centered error window buttons with improved bottom margin spacing.
  • Bug Fixes

    • Enhanced path validation and handling for render appearance configurations with support for multiple paths and improved robustness against malformed entries.

@coderabbitai
Copy link

coderabbitai bot commented Nov 6, 2025

Walkthrough

The PR enhances path handling in RevitIniReader by supporting multiple render appearance paths with quote trimming, pipe-to-semicolon conversion, per-path validation, and conditional resolution based on path rooting (absolute vs. relative). It also refines the error window UI layout with center alignment and bottom margin spacing.

Changes

Cohort / File(s) Summary
Render appearance path expansion
Common_glTF_Exporter/Utils/RevitIniReader.cs
Enhanced GetAdditionalRenderAppearancePaths to parse multiple sub-paths per entry (split on semicolon), trim quotes, replace pipes with semicolons, validate against invalid path characters, and resolve paths conditionally: rooted paths used as-is, relative paths combined with user profile. Invalid paths skipped with logging.
Error window UI refinement
Common_glTF_Exporter/Windows/ErrorWindow.xaml
Added HorizontalAlignment="Center" and Margin="0,0,0,15" to StackPanel for centered, bottom-spaced button layout.

Sequence Diagram

sequenceDiagram
    participant Code as Calling Code
    participant Reader as RevitIniReader
    participant Validator as Path Validator
    participant Resolver as Path Resolver
    
    Code->>Reader: GetAdditionalRenderAppearancePaths()
    activate Reader
    Reader->>Reader: Trim quotes, replace pipes with semicolons
    Reader->>Reader: Split on semicolons into sub-paths
    
    loop For each sub-path
        Reader->>Validator: Validate against invalid path chars
        alt Invalid path detected
            Validator-->>Reader: Skip + log warning
        else Valid path
            Validator-->>Reader: Proceed
            Reader->>Resolver: Check if rooted absolute path
            alt Rooted path
                Resolver-->>Reader: Use path as-is
            else Relative path
                Resolver-->>Reader: Combine with user profile
            end
            Reader->>Reader: Normalize path, add to results
        end
    end
    
    Reader-->>Code: Return all valid absolute paths
    deactivate Reader
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

  • RevitIniReader.cs: Path parsing logic with validation and conditional resolution requires careful inspection to ensure robustness with edge cases (empty paths, mixed rooted/relative entries, invalid characters).
  • ErrorWindow.xaml: Purely cosmetic UI property adjustments.

Possibly related PRs

  • Flipped textures #116: Initial implementation of GetAdditionalRenderAppearancePaths; this PR extends and hardens the same method with multi-path support and validation.

Poem

🐰 With pipes now semicolons split,
And paths so robustly parsed,
Each quote trimmed clean, validation fit,
While windows center, perfectly cast!
~Cheers to multi-path delight! 🎯

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Fix Illegal Characters' directly addresses the main change in RevitIniReader.cs, which adds validation to skip paths with invalid characters. However, it's somewhat vague and doesn't clearly indicate the scope (path handling in Revit INI reader).
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 86b7az61r/IllegalCharactersPath

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9167e9f and 957650e.

📒 Files selected for processing (2)
  • Common_glTF_Exporter/Utils/RevitIniReader.cs (1 hunks)
  • Common_glTF_Exporter/Windows/ErrorWindow.xaml (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (2)
Common_glTF_Exporter/Windows/ErrorWindow.xaml (1)

66-68: LGTM! Improved button layout.

The addition of horizontal centering and bottom margin improves the visual layout of the error window buttons.

Common_glTF_Exporter/Utils/RevitIniReader.cs (1)

42-49: Path cleaning logic is sound.

The double trimming and quote removal is intentional and correct:

  1. Line 42 removes outer quotes from the entire segment
  2. Line 49 removes quotes from individual sub-paths after splitting

The pipe-to-semicolon conversion effectively handles illegal path characters.

Comment on lines +51 to +56
if (Path.GetInvalidPathChars().Any(c => trimmedPath.Contains(c)))
{
// Skip or log invalid path
Console.WriteLine($"Skipping invalid path: {trimmedPath}");
continue;
}
Copy link

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:

  1. 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 cause Path.GetFullPath() to throw on lines 59-60.

  2. Console.WriteLine is 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:

#!/bin/bash
# Check if there's error handling around Path.GetFullPath calls
rg -nP --type=cs -C3 'Path\.GetFullPath\(' -g '!**/test/**'

Length of output: 1455



---

🌐 Web query:

```web
Path.GetInvalidPathChars C# .NET what characters does it return

💡 Result:

Path.GetInvalidPathChars returns a char[] clone of the internal RealInvalidPathChars array — on Windows .NET that list is:

  • '"' (double quote)
  • '<' (less-than)
  • '>' (greater-than)
  • '|' (vertical bar)
  • '\0' (null)
  • control characters U+0001 through U+001F

(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:

  1. 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 cause Path.GetFullPath() on lines 59–60 to throw an exception. Currently there is no try-catch around these calls to handle failures gracefully.

  2. 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.

Comment on lines +58 to +60
string fullPath = Path.IsPathRooted(trimmedPath)
? Path.GetFullPath(trimmedPath)
: Path.GetFullPath(Path.Combine(userProfile, trimmedPath));
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

Add exception handling for Path.GetFullPath().

Path.GetFullPath() can throw ArgumentException, PathTooLongException, NotSupportedException, and ArgumentNullException even after validation. If an invalid path slips through the validation at line 51, this will cause unhandled exceptions.

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
+                            }

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In Common_glTF_Exporter/Utils/RevitIniReader.cs around lines 58 to 60, the
Path.GetFullPath calls can still throw ArgumentException, PathTooLongException,
NotSupportedException or ArgumentNullException; wrap the path resolution in a
try-catch that catches those exceptions (or Exception if you prefer broader
safety), log or record the failure with the offending trimmedPath and exception
message, and skip or continue processing that entry (e.g., treat fullPath as
invalid and do not add it to results) so the parser does not crash when an
invalid path slips through validation.

@vnoves vnoves merged commit fa8eb19 into develop Nov 6, 2025
2 checks passed
@vnoves vnoves deleted the 86b7az61r/IllegalCharactersPath branch November 9, 2025 23:34
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.

2 participants