Skip to content

Conversation

Shane32
Copy link
Owner

@Shane32 Shane32 commented Oct 2, 2025

Roo: I've successfully fixed the GitHub issue and completed all requested tasks:

Summary of Changes

Fixed Issue

The Girocode constructor was throwing a NullReferenceException when BIC was null with Version 2, which should be allowed per the Girocode specification.

Changes Made

  1. Modified IsValidBic() in PayloadGenerator.cs:

    • Added an overload that accepts a required parameter
    • Returns true for null/empty BIC when not required
    • Returns false for null/empty BIC when required
  2. Updated Girocode constructor in Girocode.cs:

    • BIC validation now checks if it's required based on version (Version 1 requires BIC, Version 2 makes it optional)
    • Uses null-conditional operator (?.) and null-coalescing operator (??) for clean BIC handling
  3. Added comprehensive tests in GirocodeTests.cs:

    • Version 2 with null BIC (passes)
    • Version 2 with empty BIC (passes)
    • Version 2 with valid BIC (passes)
    • Version 2 with invalid BIC (throws exception)
    • Version 1 with null BIC (throws exception)
    • Version 1 with empty BIC (throws exception)

Test Results

All 23 Girocode tests passed successfully across all target frameworks (net462, netcoreapp2.1, netcoreapp3.1, net5.0, net5.0-windows, net6.0, net6.0-windows).

Branch and Commit

  • Created branch: fix/girocode-version2-bic-optional
  • Committed changes with detailed commit message
  • Pushed to remote repository

You can create a pull request at: https://github.com/Shane32/QRCoder/pull/new/fix/girocode-version2-bic-optional

Summary by CodeRabbit

  • New Features
    • Girocode v2 now accepts omitted BIC values while Girocode v1 continues to require a BIC.
  • Bug Fixes
    • Safer handling of null/empty BIC inputs and clearer validation behavior that varies by Girocode version.
  • Tests
    • Added unit tests covering presence, absence, and invalid BIC cases and related payload/output behavior.

- Modified IsValidBic to accept a 'required' parameter
- BIC is now required for Version 1 (as per spec)
- BIC is optional for Version 2 (as per spec)
- Fixed NullReferenceException when BIC is null
- Added comprehensive tests for all scenarios:
  - Version 2 with null BIC (passes)
  - Version 2 with empty BIC (passes)
  - Version 2 with valid BIC (passes)
  - Version 2 with invalid BIC (throws exception)
  - Version 1 with null BIC (throws exception)
  - Version 1 with empty BIC (throws exception)

Fixes issue where Girocode constructor threw NullReferenceException
when BIC was null with Version 2, which should be allowed per the
Girocode specification.
@Shane32 Shane32 added this to the 1.7.0 milestone Oct 2, 2025
Copy link
Contributor

coderabbitai bot commented Oct 2, 2025

Warning

Rate limit exceeded

@Shane32 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 26 minutes and 38 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 7177639 and 42d1be9.

📒 Files selected for processing (6)
  • QRCoder/PayloadGenerator.cs (1 hunks)
  • QRCoder/PayloadGenerator/Girocode.cs (1 hunks)
  • QRCoderApiTests/net35+net40+net50+net50-windows+netstandard20+netstandard21/QRCoder.approved.txt (1 hunks)
  • QRCoderApiTests/net60-windows/QRCoder.approved.txt (1 hunks)
  • QRCoderApiTests/net60/QRCoder.approved.txt (1 hunks)
  • QRCoderApiTests/netstandard13/QRCoder.approved.txt (1 hunks)
📝 Walkthrough

Walkthrough

Adds a BIC-validation overload that accepts a required flag, integrates it into Girocode (Version1 requires BIC, Version2 allows missing BIC), makes BIC normalization null‑safe, and adds unit tests for both versions and scenarios.

Changes

Cohort / File(s) Change Summary
Validation API update
QRCoder/PayloadGenerator.cs
Added private static bool IsValidBic(string bic, bool required) which returns true for null/empty when required is false, otherwise delegates to existing IsValidBic(string).
Girocode validation logic
QRCoder/PayloadGenerator/Girocode.cs
Passes requirement flag: IsValidBic(bic, _version == GirocodeVersion.Version1). Made BIC normalization null-safe: _bic = bic?.Replace(" ", "").ToUpper() ?? string.Empty;.
Unit tests for Girocode BIC handling
QRCoderTests/PayloadGeneratorTests/GirocodeTests.cs
Added tests covering Version 2 (BIC optional: null/empty/valid/invalid) and Version 1 (BIC required: null/empty error), asserting payload strings and exceptions.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Caller
  participant Girocode
  participant Validator as IsValidBic

  Caller->>Girocode: construct(..., bic, version)
  Girocode->>Validator: IsValidBic(bic, required = version==V1)

  alt required (Version1)
    Validator-->>Girocode: false (invalid or missing)
    Girocode-->>Caller: throw GirocodeException("The BIC is invalid.")
    Validator-->>Girocode: true (valid)
    Girocode-->>Caller: payload includes BIC
  else optional (Version2)
    alt bic null/empty
      Validator-->>Girocode: true
      Girocode-->>Caller: payload omits BIC
    else bic present
      Validator->>Validator: validate format (existing logic)
      Validator-->>Girocode: true/false
      alt valid
        Girocode-->>Caller: payload includes BIC
      else invalid
        Girocode-->>Caller: throw GirocodeException("The BIC is invalid.")
      end
    end
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • gfoidl

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 30.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 succinctly describes the primary change—making BIC optional for Girocode Version 2—directly reflecting the fix implemented in the pull request and aligning with its objectives.

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
Contributor

@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: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 30afd17 and 7177639.

📒 Files selected for processing (3)
  • QRCoder/PayloadGenerator.cs (1 hunks)
  • QRCoder/PayloadGenerator/Girocode.cs (1 hunks)
  • QRCoderTests/PayloadGeneratorTests/GirocodeTests.cs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • QRCoder/PayloadGenerator.cs
🧰 Additional context used
🧬 Code graph analysis (2)
QRCoder/PayloadGenerator/Girocode.cs (1)
QRCoder/PayloadGenerator.cs (2)
  • IsValidBic (65-66)
  • IsValidBic (74-79)
QRCoderTests/PayloadGeneratorTests/GirocodeTests.cs (2)
QRCoder/PayloadGenerator.cs (1)
  • PayloadGenerator (10-146)
QRCoder/PayloadGenerator/Girocode.cs (8)
  • PayloadGenerator (3-207)
  • Girocode (8-206)
  • Girocode (39-69)
  • ToString (75-95)
  • GirocodeException (178-205)
  • GirocodeException (183-185)
  • GirocodeException (191-194)
  • GirocodeException (201-204)
🪛 GitHub Actions: Format (Pull Request)
QRCoderTests/PayloadGeneratorTests/GirocodeTests.cs

[error] 335-335: CS8625: Cannot convert null literal to non-nullable reference type.

🪛 GitHub Check: format
QRCoderTests/PayloadGeneratorTests/GirocodeTests.cs

[failure] 425-425:
Cannot convert null literal to non-nullable reference type.


[failure] 335-335:
Cannot convert null literal to non-nullable reference type.


[failure] 425-425:
Cannot convert null literal to non-nullable reference type.


[failure] 335-335:
Cannot convert null literal to non-nullable reference type.


[failure] 425-425:
Cannot convert null literal to non-nullable reference type.


[failure] 335-335:
Cannot convert null literal to non-nullable reference type.


[failure] 425-425:
Cannot convert null literal to non-nullable reference type.


[failure] 335-335:
Cannot convert null literal to non-nullable reference type.


[failure] 425-425:
Cannot convert null literal to non-nullable reference type.


[failure] 335-335:
Cannot convert null literal to non-nullable reference type.

⏰ 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). (2)
  • GitHub Check: additional-tests
  • GitHub Check: build
🔇 Additional comments (1)
QRCoderTests/PayloadGeneratorTests/GirocodeTests.cs (1)

325-457: Excellent test coverage for BIC handling across versions.

The test suite comprehensively covers all scenarios:

  • Version2: null, empty, valid, and invalid BIC cases
  • Version1: null and empty BIC validation

Test assertions correctly verify both successful payload generation and appropriate exception handling. Once the bic parameter signature is updated to nullable in the production code, the compiler warnings will be resolved.

@Shane32 Shane32 self-assigned this Oct 5, 2025
@Shane32 Shane32 requested a review from gfoidl October 5, 2025 15:22
Copy link
Collaborator

@gfoidl gfoidl left a comment

Choose a reason for hiding this comment

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

Modulo the nits looks good to me.

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.

Girocode / PayloadGenerator, BIC validation errors when not passed in to Girocode constructor, with SCT version set to 2

2 participants