Skip to content

Conversation

@breardon2011
Copy link
Contributor

Summary

Fixes #2510

This PR fixes a critical bug where URL-encoded characters (like %2F) in Terraform resource IDs were being corrupted into %!(MISSING)F(MISSING) in GitHub PR comments.

Root Cause

The issue was caused by incorrect use of fmt.Sprintf where Terraform output containing URL-encoded characters was passed as format arguments. Go's fmt.Sprintf interprets % characters as format verbs, causing the corruption when strings like %2F were encountered.

Changes Made

  • backend/controllers/projects_helpers.go: Replaced fmt.Sprintf with string concatenation for Terraform output
  • backend/utils/comment_utils.go: Added strings.ReplaceAll to escape % characters in URLs and project names
  • libs/comment_utils/summary/updater.go: Applied same escaping in CLI comment updater
  • libs/comment_utils/reporting/source_grouping.go: Escaped project names and locations in grouped reporting
  • cli/pkg/drift/github_issue.go: Used string concatenation for drift messages
  • ee/cli/pkg/comment_updater/updater.go: Escaped all user-controlled strings in EE updater

Testing

The fix ensures that:

  • URL-encoded characters in resource IDs are preserved correctly
  • Terraform plan output is displayed accurately in PR comments
  • No format verb interpretation occurs on user-controlled strings

Impact

This fix particularly affects:

  • Google Cloud resources with URL-encoded IDs (e.g., google_service_networking_connection)
  • Any Terraform resources containing / or other special characters in their IDs
  • GitHub workflow URLs or check run URLs with encoded characters

🤖 Generated with Claude Code

… output

Fixes diggerhq#2510

The issue was caused by incorrect use of fmt.Sprintf where Terraform output
containing URL-encoded characters (like %2F) was passed as a format argument.
Go's fmt.Sprintf interpreted these percent signs as format verbs, resulting
in corrupted output like %!(MISSING)F(MISSING).

Changes made:
- backend/controllers/projects_helpers.go: Use string concatenation instead
  of fmt.Sprintf for Terraform output to avoid format verb interpretation
- backend/utils/comment_utils.go: Escape percent signs in URLs and project
  names by replacing % with %% in fmt.Sprintf calls
- libs/comment_utils/summary/updater.go: Apply same escaping for CLI updater
- libs/comment_utils/reporting/source_grouping.go: Escape project names and
  locations in grouped reporting
- cli/pkg/drift/github_issue.go: Use string concatenation for drift messages
  containing Terraform plan output
- ee/cli/pkg/comment_updater/updater.go: Escape all user-controlled strings
  in EE comment updater

The fix ensures that URL-encoded characters and any other percent signs in
resource IDs, URLs, and project names are properly handled and displayed
correctly in GitHub PR comments.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@breardon2011
Copy link
Contributor Author

breardon2011 commented Dec 13, 2025

this was a test written by the ai project, ignore

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.

URL-Encoding in Resource IDs (%2F) in Terraform Output Cause Corrupted Digger Comments

1 participant