Skip to content

Conversation

@Shane32
Copy link
Owner

@Shane32 Shane32 commented Oct 2, 2025

Summary by CodeRabbit

  • New Features

    • Added explicit address type support for contact QR payloads (Home, Work, HomePreferred, WorkPreferred).
    • Improved ADR composition and type mapping across vCard 2.1/3.0/4.0 and MeCard.
    • Default address type now defaults to HomePreferred when not specified.
  • Documentation

    • Included vCard 3.0 (RFC 2426) reference for formatting rules.
  • Tests

    • Added tests for work and preferred address outputs; updated expected MECARD/VCARD ADR strings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 2, 2025

📝 Walkthrough

Walkthrough

Adds address-type support to ContactData via a new public nested AddressType enum and constructor overloads; updates vCard/MeCard ADR generation with version-specific address-type mappings and reordered ADR fields; adds an RFC 2426 vCard 3.0 reference file; updates and adds unit tests for address formatting.

Changes

Cohort / File(s) Summary
ContactData address type support
QRCoder/PayloadGenerator/ContactData.cs
Added public nested AddressType enum (Home, Work, HomePreferred, WorkPreferred); added constructor overload that accepts AddressType and a delegating overload with default HomePreferred; extended ToString to include address type strings for vCard 2.1/3.0/4.0 and MeCard; added helper methods to map AddressType to version-specific type tokens; adjusted ADR field ordering/formatting.
Documentation addition (RFC 2426 reference)
QRCoder/PayloadGenerator/ContactData_vCard3_rfc2426.txt
Added vCard 3.0 (RFC 2426) specification reference file.
Unit tests for address formatting
QRCoderTests/PayloadGeneratorTests/ContactDataTests.cs
Updated expected ADR sequences in existing MECARD/VCARD tests to match new ADR ordering; added tests verifying VCARD3 work address and VCARD4 work-preferred address outputs.
API approval snapshots
QRCoderApiTests/.../QRCoder.approved.txt
Public API updated to include new AddressType enum and constructor overloads across targeted frameworks (netstandard/netcore/net). Approval files updated accordingly.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Caller
  participant ContactData
  participant Formatter as VCard/Mecard Formatter

  Caller->>ContactData: new ContactData(..., AddressType?) 
  activate ContactData
  ContactData->>ContactData: store fields and _addressType (default HomePreferred if absent)
  deactivate ContactData

  Caller->>ContactData: ToString(outputType)
  activate ContactData
  ContactData->>Formatter: select format rules (v2.1 / v3.0 / v4.0 / MECARD)
  Formatter-->>ContactData: format spec
  ContactData->>ContactData: Map AddressType -> version tokens (GetAddressTypeString21/3/4)
  ContactData->>ContactData: compose ADR with reordered fields and type qualifiers
  ContactData-->>Caller: return formatted payload string
  deactivate ContactData
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title accurately references vCard fixes and the import of RFC documents which are present in the changeset, but it is broad and does not highlight the key enhancement of address type support for contacts which is the primary feature introduced.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix_vcard

📜 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 f83fb05 and 211398e.

📒 Files selected for processing (4)
  • QRCoderApiTests/net35+net40+net50+net50-windows+netstandard20/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)
⏰ 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

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: 0

🧹 Nitpick comments (2)
QRCoder/PayloadGenerator/ContactData_vCard3_rfc2426.txt (1)

1-2356: Consider referencing the RFC instead of including the full text.

Including the complete RFC 2426 specification (2,356 lines) significantly increases repository size. Since RFCs are immutable, publicly available documents, consider replacing this file with:

  1. A brief comment in the code referencing "RFC 2426 - vCard MIME Directory Profile"
  2. A link in the documentation to https://www.ietf.org/rfc/rfc2426.txt

This approach is more maintainable and is the standard practice in most open-source projects.

QRCoder/PayloadGenerator/ContactData.cs (1)

253-296: Consider throwing an exception for unhandled AddressType values.

The three helper methods currently return a default string ("HOME;PREF", "HOME,PREF", or "home,pref") for any unhandled AddressType values. If the AddressType enum is extended in the future, this could lead to silent incorrect behavior.

Consider either:

  1. Throwing an ArgumentOutOfRangeException in the default case to catch unhandled values during development
  2. Explicitly mapping the default case to AddressType.HomePreferred for clarity

Example:

 private string GetAddressTypeString21()
 {
     return _addressType switch
     {
         AddressType.Home => "HOME",
         AddressType.Work => "WORK",
         AddressType.HomePreferred => "HOME;PREF",
         AddressType.WorkPreferred => "WORK;PREF",
-        _ => "HOME;PREF"
+        _ => throw new ArgumentOutOfRangeException(nameof(_addressType), _addressType, "Unknown address type")
     };
 }
📜 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 f83fb05.

📒 Files selected for processing (3)
  • QRCoder/PayloadGenerator/ContactData.cs (6 hunks)
  • QRCoder/PayloadGenerator/ContactData_vCard3_rfc2426.txt (1 hunks)
  • QRCoderTests/PayloadGeneratorTests/ContactDataTests.cs (5 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
QRCoderTests/PayloadGeneratorTests/ContactDataTests.cs (1)
QRCoder/PayloadGenerator/ContactData.cs (5)
  • PayloadGenerator (5-369)
  • ContactData (10-368)
  • ContactData (58-61)
  • ContactData (87-110)
  • ToString (116-251)
⏰ 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 (12)
QRCoderTests/PayloadGeneratorTests/ContactDataTests.cs (6)

50-50: LGTM!

The updated expected string correctly reflects the MeCard ADR format with address components in the proper order (PO Box, Extended Address, Street, Locality, Region, Postal Code, Country).


108-108: LGTM!

The updated expected string correctly includes the vCard 2.1 address type format (ADR;HOME;PREF:) and follows RFC 2426 Section 3.2.1 structure for address components.


137-137: LGTM!

The updated expected string correctly uses vCard 3.0 TYPE parameter syntax (ADR;TYPE=HOME,PREF:) with comma-separated type values, consistent with RFC 2426 Section 3.2.1.


166-166: LGTM!

The updated expected string correctly uses vCard 4.0 lowercase TYPE parameter syntax (ADR;TYPE=home,pref:), consistent with vCard 4.0 conventions.


198-223: LGTM!

The new test correctly validates work address generation for vCard 3.0. It properly:

  • Passes AddressType.Work explicitly to the constructor
  • Expects the correct vCard 3.0 TYPE format (ADR;TYPE=WORK:)
  • Handles empty state/region field correctly (double semicolon)
  • Follows the established test pattern

225-250: LGTM!

The new test correctly validates work preferred address generation for vCard 4.0. It properly:

  • Passes AddressType.WorkPreferred explicitly to the constructor
  • Expects the correct vCard 4.0 lowercase TYPE format with PREF (ADR;TYPE=work,pref:)
  • Handles empty state/region field correctly (double semicolon)
  • Follows the established test pattern
QRCoder/PayloadGenerator/ContactData.cs (6)

32-32: LGTM!

The private readonly field _addressType follows C# naming conventions and is consistent with other fields in the class.


58-61: LGTM!

The delegating constructor maintains backward compatibility by supplying a default AddressType.HomePreferred, which matches the previous behavior of the class. This is the standard C# pattern for extending constructors without breaking existing callers.


63-110: LGTM!

The new constructor properly extends the existing functionality by:

  • Including comprehensive XML documentation for the new addressType parameter
  • Maintaining all existing parameter assignments
  • Adding the addressType assignment at the appropriate location
  • Following logical parameter ordering (address type after address fields)

142-152: LGTM!

The updated comment references RFC 2426 Section 3.2.1, providing helpful context. The MeCard address format correctly omits address type (not supported by MeCard format) and uses comma separators as per MeCard specifications.


217-234: LGTM!

The vCard address formatting correctly:

  • References RFC 2426 Section 3.2.1 for ADR structure
  • Differentiates address type syntax by vCard version (2.1 semicolon-separated, 3.0/4.0 TYPE= comma-separated)
  • Uses semicolon field separators per vCard specification
  • Follows the RFC 2426 ADR component order: PO Box; Extended Address; Street; Locality; Region; Postal Code; Country

298-322: LGTM!

The AddressType enum is well-designed with:

  • Clear, comprehensive XML documentation
  • Appropriate values covering common use cases (Home, Work, HomePreferred, WorkPreferred)
  • Explicit note about HomePreferred being the default for backward compatibility
  • Proper C# naming conventions
  • Logical nesting within the ContactData class

@Shane32 Shane32 self-assigned this Oct 2, 2025
@Shane32 Shane32 added this to the 1.7.0 milestone Oct 2, 2025
@Shane32 Shane32 requested a review from gfoidl October 2, 2025 04:27
@Shane32
Copy link
Owner Author

Shane32 commented Oct 2, 2025

While there's lots of improvements that could be done with vCard support, this at least covers the outstanding issues.

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.

this at least covers the outstanding issues.

Please link them in the description here, so they can get auto-closed.

@Shane32
Copy link
Owner Author

Shane32 commented Oct 2, 2025

They are linked on the right side and will get auto closed:
image
It also gets added to the PR history:
image
I always manually link PRs to issues, and don't rely on GitHub to read the "closes" tags in the summary.

@Shane32 Shane32 merged commit 13c10ff into master Oct 2, 2025
12 checks passed
@Shane32 Shane32 deleted the fix_vcard branch October 2, 2025 13:14
@gfoidl
Copy link
Collaborator

gfoidl commented Oct 2, 2025

I always manually link PRs to issues

Ah, good to know.
I knew that GH links them when the message has the issues mentioned with a correct format, but didn't know that manual linking also works. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants