Skip to content

Fix Contacts vCard escaping and group orphan cleanup#38

Merged
oleksandr-nc merged 1 commit into
mainfrom
feature/p3-contacts-fixes
Apr 7, 2026
Merged

Fix Contacts vCard escaping and group orphan cleanup#38
oleksandr-nc merged 1 commit into
mainfrom
feature/p3-contacts-fixes

Conversation

@bigcat88
Copy link
Copy Markdown
Contributor

@bigcat88 bigcat88 commented Apr 7, 2026

Summary

Follow-up to #37 (Contacts tools). Fixes three issues found during review:

  • ORG semicolon escaping: _vcard_escape_org preserves ; as the RFC 2426 component separator instead of escaping it. Ensures ORG:Acme Inc;Engineering;Backend round-trips correctly through read→update→write.
  • Missing N field for semicolon names: _build_vcard now sanitizes ; in full_name before synthesizing the required N field, instead of silently skipping N generation (violating vCard 3.0).
  • Orphaned group labels: _strip_updated_fields now removes X-ABLabel / X-ABRelatedNames metadata lines when all real properties in their group are stripped (e.g., replacing grouped EMAIL entries).

Test plan

  • test_create_full_name_with_semicolon_has_n_field — N field present when full_name contains ;
  • test_update_multicomponent_org_roundtrip — multi-component ORG survives read→update→write
  • test_update_email_strips_orphan_group_labels — X-ABLabel removed with orphaned group
  • test_update_email_preserves_tel_in_same_group — mixed group keeps non-stripped fields
  • test_update_tel_preserves_email_in_same_group — mirror test for TEL updates
  • CI

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Better handling of semicolons in contact organization and name fields, preserving literal separators where appropriate and sanitizing when needed.
    • Improved consistency for grouped contact properties so orphaned metadata labels are removed when their group entries are deleted.
    • Updates to organization edits now round-trip without corrupting multi-component or escaped values.
  • Tests

    • Added integration tests covering semicolon edge cases and grouped-property update behaviors.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 7, 2026

Warning

Rate limit exceeded

@bigcat88 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 6 minutes and 36 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 6 minutes and 36 seconds.

⌛ 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.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f603901a-aaa0-4ca2-99c6-68a1d5e550dc

📥 Commits

Reviewing files that changed from the base of the PR and between f620ec1 and 9ae5b0e.

📒 Files selected for processing (2)
  • src/nc_mcp_server/tools/contacts.py
  • tests/integration/test_contacts.py
📝 Walkthrough

Walkthrough

Updated vCard handling: added ORG-specific parsing/escaping to preserve semicolon-delimited organization components and improved grouped-property stripping to remove orphaned group metadata when contact fields are updated. Tests added for semicolon and grouped-property edge cases.

Changes

Cohort / File(s) Summary
vCard ORG & escaping
src/nc_mcp_server/tools/contacts.py
Added raw-ORG extraction and _vcard_escape_org() logic; emit ORG: with preserved semicolon separators; sanitize N: generation for full_name containing semicolons.
Grouped-property stripping & updates
src/nc_mcp_server/tools/contacts.py
Enhanced _strip_updated_fields() to detect itemN.* grouped properties and remove orphaned group metadata (e.g., X-ABLabel) when all non-metadata group properties are skipped; _apply_contact_updates() uses ORG-specific escaping for scalar ORG updates.
Integration tests
tests/integration/test_contacts.py
Added tests for full-name semicolon round-trip, multi-component ORG preservation and literal escaped-semicolon preservation, and grouped-property update scenarios (email/tel group label cleanup and preservation checks).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 I hop through vCards, nibbling strings,

Semicolons kept where the org-name sings;
Labels trimmed when their neighbors go,
Components safe in a tidy row;
A happy rabbit tidies vCard snow.

🚥 Pre-merge checks | ✅ 3
✅ 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 directly and concisely summarizes the two main fixes: vCard escaping for ORG fields and cleanup of orphaned group labels. It accurately reflects the core objectives of the changeset.
Docstring Coverage ✅ Passed Docstring coverage is 80.95% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/p3-contacts-fixes

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.

@bigcat88 bigcat88 force-pushed the feature/p3-contacts-fixes branch from e1a48c1 to 8660832 Compare April 7, 2026 09:04
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 7, 2026

Codecov Report

❌ Patch coverage is 95.52239% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.06%. Comparing base (6daba5a) to head (9ae5b0e).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/nc_mcp_server/tools/contacts.py 95.52% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #38      +/-   ##
==========================================
- Coverage   96.09%   96.06%   -0.04%     
==========================================
  Files          25       25              
  Lines        2282     2336      +54     
==========================================
+ Hits         2193     2244      +51     
- Misses         89       92       +3     
Flag Coverage Δ
integration 94.99% <95.52%> (-0.02%) ⬇️
nc32 94.99% <95.52%> (-0.02%) ⬇️
nc33 94.94% <95.52%> (-0.02%) ⬇️
py3.12 7.83% <0.00%> (-0.19%) ⬇️
py3.13 7.83% <0.00%> (-0.19%) ⬇️
py3.14 7.83% <0.00%> (-0.19%) ⬇️
session-cache 22.64% <5.97%> (-0.37%) ⬇️
unit 7.83% <0.00%> (-0.19%) ⬇️
user-permissions 41.86% <5.97%> (-0.82%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@oleksandr-nc oleksandr-nc marked this pull request as ready for review April 7, 2026 10:43
Copy link
Copy Markdown

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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/nc_mcp_server/tools/contacts.py`:
- Around line 51-53: The helper _vcard_escape_org currently splits a
semicolon-joined string which loses information for already-escaped '\;'
sequences; fix by treating ORG as structured components end-to-end: stop passing
a pre-joined string into _vcard_escape_org (the code that flattens ORG before
calling it) and change _vcard_escape_org to accept an iterable/sequence of
components (or add a new helper like _vcard_escape_org_components) that calls
_vcard_escape on each component and then joins with ";" — alternatively, if you
must accept strings, implement a split that respects backslash-escaping (i.e.,
split on unescaped ';') so literal '\;' inside a component is preserved. Ensure
callers that previously joined the components are updated to pass the component
list or the properly split string to the new helper.
- Around line 321-352: The function _strip_updated_fields incorrectly treats
X-ABRELATEDNAMES and X-ABDATE as pure group-metadata (via
_GROUP_METADATA_FIELDS), causing user data to be dropped when a group's real
properties are stripped; update the logic by removing X-ABRELATEDNAMES and
X-ABDATE from _GROUP_METADATA_FIELDS (leaving only true metadata like X-ABLABEL)
so group_real only excludes genuine metadata and orphan_groups is computed
correctly, ensuring fields like X-ABRELATEDNAMES and X-ABDATE are preserved by
_strip_updated_fields.

In `@tests/integration/test_contacts.py`:
- Around line 736-742: The assertion checking for orphan X-ABLabel lines is
case-sensitive and can miss variants like "X-ABLABEL"; update the check in the
test that calls nc_mcp.client.dav_request (uses variable body) to perform a
case-insensitive search (e.g., normalize body to lowercase or use a
case-insensitive regex) and assert that "x-ablabel" (lowercased) is not present;
keep the same failure message but ensure it reflects the normalized comparison.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ee85d45d-1ea0-49db-b7fb-3e00c21c32c2

📥 Commits

Reviewing files that changed from the base of the PR and between 6daba5a and 8660832.

📒 Files selected for processing (2)
  • src/nc_mcp_server/tools/contacts.py
  • tests/integration/test_contacts.py

Comment thread src/nc_mcp_server/tools/contacts.py Outdated
Comment thread src/nc_mcp_server/tools/contacts.py Outdated
Comment thread tests/integration/test_contacts.py Outdated
@bigcat88 bigcat88 force-pushed the feature/p3-contacts-fixes branch from 8660832 to f620ec1 Compare April 7, 2026 11:37
Copy link
Copy Markdown

@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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/nc_mcp_server/tools/contacts.py`:
- Around line 86-99: The ORG round-trip loses information because
_extract_raw_org only re-escapes semicolons and not backslashes, so components
that end with a literal backslash become ambiguous; fix by escaping backslashes
before escaping semicolons when reconstructing the flat value (i.e., for each
component in _extract_raw_org and the inverse in
_vcard_escape_org/_parse_org_components, replace "\" with "\\" first, then
replace ";" with "\;") so trailing backslashes are preserved and the original
component boundaries remain recoverable.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8554e314-c10e-49e5-8ae1-bdfcd4978aee

📥 Commits

Reviewing files that changed from the base of the PR and between 8660832 and f620ec1.

📒 Files selected for processing (2)
  • src/nc_mcp_server/tools/contacts.py
  • tests/integration/test_contacts.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/integration/test_contacts.py

Comment thread src/nc_mcp_server/tools/contacts.py Outdated
@bigcat88 bigcat88 force-pushed the feature/p3-contacts-fixes branch from f620ec1 to 908da47 Compare April 7, 2026 11:58
@bigcat88 bigcat88 force-pushed the feature/p3-contacts-fixes branch from 908da47 to 9ae5b0e Compare April 7, 2026 11:59
@oleksandr-nc oleksandr-nc merged commit 9e68de6 into main Apr 7, 2026
12 checks passed
@oleksandr-nc oleksandr-nc deleted the feature/p3-contacts-fixes branch April 7, 2026 12:22
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.

2 participants