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 supports optional BIC: you can omit the BIC and still generate a valid code.
  • Bug Fixes
    • Improved validation to provide clearer feedback for invalid BICs.
    • Safer handling of empty or missing BIC values to prevent failures during Girocode generation.
  • Tests
    • Added comprehensive tests covering BIC presence, absence, and invalid cases across Girocode v1 and v2.

- 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

coderabbitai bot commented Oct 2, 2025

📝 Walkthrough

Walkthrough

Adds an optional-requirement overload for BIC validation and integrates it into Girocode generation: Version 1 requires a BIC; Version 2 allows empty/absent BIC. Also makes BIC normalization null-safe. New unit tests cover both versions and scenarios (null, empty, valid, invalid BIC).

Changes

Cohort / File(s) Change Summary
Validation API update
QRCoder/PayloadGenerator.cs
Added overload IsValidBic(string bic, bool required). Returns true for null/empty when required is false; otherwise delegates to existing IsValidBic(string). No change to original validation logic.
Girocode validation logic
QRCoder/PayloadGenerator/Girocode.cs
Updated BIC validation to 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 for Version 2 allowing null/empty BIC, and Version 1 requiring BIC. Verified valid/invalid cases and ToString outputs with/without BIC.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant C as Caller
  participant G as Girocode (ctor/ToString)
  participant V as PayloadGenerator.IsValidBic
  Note over C,G: Create Girocode payload

  alt Version 1 (BIC required)
    C->>G: new Girocode(..., bic, Version1)
    G->>V: IsValidBic(bic, required=true)
    alt bic null/empty/invalid
      V-->>G: false
      G-->>C: throw GirocodeException("The BIC is invalid.")
    else valid
      V-->>G: true
      G-->>C: payload with BIC
    end
  else Version 2 (BIC optional)
    C->>G: new Girocode(..., bic, Version2)
    G->>V: IsValidBic(bic, required=false)
    alt bic null/empty
      V-->>G: true
      G-->>C: payload without BIC
    else bic present
      V->>V: IsValidBic(bic) // existing validator
      alt invalid
        V-->>G: false
        G-->>C: throw GirocodeException("The BIC is invalid.")
      else valid
        V-->>G: true
        G-->>C: payload with BIC
      end
    end
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

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 concisely and accurately describes the primary change by highlighting that the BIC becomes optional for Girocode Version 2, directly reflecting the PR’s main objective to fix the NullReferenceException and align with the specification. It is clear, specific, and free of extraneous details. This phrasing ensures that anyone scanning the history immediately understands the core update.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/girocode-version2-bic-optional

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

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

📒 Files selected for processing (3)
  • QRCoder/PayloadGenerator.cs (1 hunks)
  • QRCoder/PayloadGenerator/Girocode.cs (1 hunks)
  • QRCoderTests/PayloadGeneratorTests/GirocodeTests.cs (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
QRCoder/PayloadGenerator/Girocode.cs (1)
QRCoder/PayloadGenerator.cs (2)
  • IsValidBic (70-71)
  • IsValidBic (79-84)
QRCoderTests/PayloadGeneratorTests/GirocodeTests.cs (2)
QRCoder/PayloadGenerator.cs (1)
  • PayloadGenerator (15-151)
QRCoder/PayloadGenerator/Girocode.cs (8)
  • PayloadGenerator (5-209)
  • Girocode (10-208)
  • Girocode (41-71)
  • ToString (77-97)
  • GirocodeException (180-207)
  • GirocodeException (185-187)
  • GirocodeException (193-196)
  • GirocodeException (203-206)
⏰ 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). (1)
  • GitHub Check: build
🔇 Additional comments (3)
QRCoder/PayloadGenerator/Girocode.cs (1)

48-50: LGTM! Correct implementation of version-specific BIC validation.

The changes correctly enforce BIC requirement for Version 1 while allowing optional BIC for Version 2, and the null-safe assignment prevents the NullReferenceException.

QRCoder/PayloadGenerator.cs (1)

73-84: LGTM! Clean implementation of conditional BIC validation.

The new overload correctly handles optional BIC validation by returning !required for null/empty values and delegating to the existing validation method otherwise.

QRCoderTests/PayloadGeneratorTests/GirocodeTests.cs (1)

348-480: LGTM! Comprehensive test coverage for BIC validation.

The test suite thoroughly covers all scenarios:

  • Version 2: null, empty, valid, and invalid BIC inputs
  • Version 1: null and empty BIC rejection

All assertions correctly verify both successful payload generation and exception handling.


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.

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
1 participant