Skip to content

fix: add null guard in HexSKColorToByteArray to resolve S2259#87

Merged
afonsoft merged 1 commit into
feature/devin-20260712-sonar-qualityfrom
feature/devin-20260712-sonar-null-guard
Jul 12, 2026
Merged

fix: add null guard in HexSKColorToByteArray to resolve S2259#87
afonsoft merged 1 commit into
feature/devin-20260712-sonar-qualityfrom
feature/devin-20260712-sonar-null-guard

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

All Submissions:

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?

New Feature Submissions:

  1. Does your submission pass tests?
  2. Have you lint your code locally prior to submission?

Changes to Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully ran tests with your changes locally?

fix: add null guard in HexSKColorToByteArray to resolve S2259

The HexSKColorToByteArray methods in PdfByteQRCode and BitmapByteQRCode replaced the previous !string.IsNullOrEmpty(...) checks with an explicit string.IsNullOrEmpty(...) guard that throws ArgumentException. This ensures colorString is non-null and non-empty before Substring is called, resolving the SonarCloud S2259 issue reported on the renderer phase.

Build and dotnet test QRCoder.Core.Tests/ -f net10.0 --configuration Release pass locally (502 tests).

Link to Devin session: https://app.devin.ai/sessions/20c92a1bad724f63b8be89a9e195e664
Requested by: @afonsoft


Open in Devin Review

Co-Authored-By: Afonso Dutra Nogueira Filho <afonsoft@gmail.com>
@afonsoft afonsoft self-assigned this Jul 12, 2026
@afonsoft
afonsoft self-requested a review July 12, 2026 17:51
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@sonarqubecloud

Copy link
Copy Markdown

@afonsoft
afonsoft merged commit 522b1c8 into feature/devin-20260712-sonar-quality Jul 12, 2026
5 of 6 checks passed
@afonsoft
afonsoft deleted the feature/devin-20260712-sonar-null-guard branch July 12, 2026 17:52

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Devin Review found 2 potential issues.

Open in Devin Review

Comment on lines +115 to +116
if (string.IsNullOrEmpty(colorString))
throw new ArgumentException("Color string cannot be null or empty.", nameof(colorString));

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

📝 Info: Behavioral change from silent degradation to exception for empty color strings

The old code silently handled empty color strings by producing a zero-length byte array (which would result in corrupted BMP/PDF output). The new code throws ArgumentException instead. While this is a better behavior, it is technically a breaking change for any consumer that previously relied on passing empty strings without getting an exception. I verified all current internal callers (BitmapByteQRCode.cs:52, PdfByteQRCode.cs:72, and the helper classes) and none pass null or empty — they use either hardcoded hex strings like "#000000" or forward user-provided parameters. However, since these are public API methods (GetGraphic at BitmapByteQRCode.cs:50 and PdfByteQRCode.cs:63), external consumers could be affected.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +218 to +219
if (string.IsNullOrEmpty(colorString))
throw new ArgumentException("Color string cannot be null or empty.", nameof(colorString));

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

📝 Info: Duplicated HexSKColorToByteArray implementation across two files

The HexSKColorToByteArray method is identically implemented in both BitmapByteQRCode.cs:113-122 and PdfByteQRCode.cs:216-225. This PR applied the same fix to both copies, but the duplication itself is a maintenance risk — future fixes or enhancements would need to be applied in both places. Consider extracting this into a shared utility (e.g., in the Extensions/ folder) to follow the DRY principle.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

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.

1 participant