Skip to content

Conversation

Copy link
Contributor

Copilot AI commented May 28, 2025

The HTML autotrim feature was incorrectly computing common prefixes that could end in the middle of directory names, causing partial directory names to be stripped from file paths.

Problem

When multiple SARIF results had file paths with similar prefixes that didn't align with directory boundaries, the autotrim logic would compute a common prefix that cut through directory names. For example:

Input paths:

tools/bin/RedacteA/RedacteB/RedacteB.deps.json
tools/bin/RedacteC/RedacteD/RedacteD.deps.json  

Before fix: Common prefix computed as tools/bin/Redacte, resulting in broken output:

ools/bin/RedacteA/RedacteB/RedacteB.deps.json:953
ools/bin/RedacteC/RedacteD/RedacteD.deps.json:960

After fix: Common prefix computed as tools/bin/, resulting in correct output:

RedacteA/RedacteB/RedacteB.deps.json:953
RedacteC/RedacteD/RedacteD.deps.json:960

Solution

Modified the init_path_prefix_stripping method in sarif_file.py to ensure that computed common prefixes always end at directory boundaries (slashes). The fix:

  1. Finds the common prefix between paths as before
  2. Locates the last directory separator (slash) in the common prefix
  3. Truncates the prefix to end at that directory boundary
  4. If no directory separator is found, disables autotrim for that case

Testing

Added comprehensive tests covering:

  • The original bug case with partial directory name prefixes
  • Paths with no common directory prefix (autotrim disabled)
  • Paths with proper common directory prefixes (autotrim works correctly)
  • Edge cases with deeply nested paths

All existing tests continue to pass, ensuring no regressions.

Fixes #85.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: gramster <2762632+gramster@users.noreply.github.com>
Copilot AI changed the title [WIP] HTML autotrim bug Fix HTML autotrim bug - respect directory boundaries when computing common prefix May 28, 2025
Copilot AI requested a review from gramster May 28, 2025 17:35
@LensPlaysGames
Copy link

fixes #110

oops. lgtm???

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.

HTML autotrim bug

3 participants