Skip to content

Conversation

@stympy
Copy link
Member

@stympy stympy commented Oct 9, 2025

Fixes #733

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes handling of invalid UTF-8 byte sequences in strings during sanitization to prevent ArgumentError exceptions. The fix ensures that strings with invalid encodings are properly handled before pattern matching operations.

  • Added encoding validation before regex pattern matching in the inspected? method
  • Added comprehensive test coverage for objects with invalid byte sequences in their string representations
  • Implemented graceful error handling with fallback behavior when encoding issues occur

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
lib/honeybadger/util/sanitizer.rb Added encoding validation and error handling to inspected? method to prevent crashes on invalid UTF-8
spec/unit/honeybadger/util/sanitizer_spec.rb Added test cases covering invalid byte sequences and inspect-like strings with encoding issues

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

String(string) =~ /#<.*>/
# Ensure string has valid encoding before pattern matching
# to avoid ArgumentError with invalid byte sequences
string = valid_encoding(string) unless valid_encoding?(string)
Copy link

Copilot AI Oct 9, 2025

Choose a reason for hiding this comment

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

The valid_encoding method is called but not defined in this class. This will raise a NoMethodError. You should either define this method or use Ruby's built-in string encoding methods like string.scrub to handle invalid encodings.

Copilot uses AI. Check for mistakes.
String(string) =~ /#<.*>/
# Ensure string has valid encoding before pattern matching
# to avoid ArgumentError with invalid byte sequences
string = valid_encoding(string) unless valid_encoding?(string)
Copy link

Copilot AI Oct 9, 2025

Choose a reason for hiding this comment

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

The valid_encoding? method is called but not defined in this class. This should use Ruby's built-in String#valid_encoding? method by calling it on the string object: string.valid_encoding?.

Copilot uses AI. Check for mistakes.
@stympy stympy merged commit e707cc8 into master Oct 10, 2025
90 checks passed
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.

Sanitizer#inspected? raises encoding errors when data contains invalid byte sequences

3 participants