Skip to content

fix: sanitize custom IM type label before using as IMPP URI scheme#543

Open
faraz152 wants to merge 1 commit intoFossifyOrg:mainfrom
faraz152:fix/499-im-custom-type-space-export
Open

fix: sanitize custom IM type label before using as IMPP URI scheme#543
faraz152 wants to merge 1 commit intoFossifyOrg:mainfrom
faraz152:fix/499-im-custom-type-space-export

Conversation

@faraz152
Copy link
Copy Markdown

What

Fixes #499

A contact with a custom IM type containing a space (e.g. "a b") caused sharing/export to fail silently — a 0-byte file was written and an error toast appeared.

Root cause

VcfExporter passes it.label directly as the protocol argument to ez-vcard's Impp(String protocol, String handle) constructor. That constructor builds a java.net.URI using the protocol string as the URI scheme. URI schemes only allow [a-zA-Z][a-zA-Z0-9+-.]*, so a label containing a space throws IllegalArgumentException, which propagates up and aborts the export.

Fix

Before constructing the Impp property, replace any character outside the valid URI-scheme set with a hyphen. Two additional guards:

  • Labels that start with a non-letter are prefixed with "x-" (scheme must begin with ALPHA)
  • Empty labels fall back to "x-custom"

Testing

Manually verified:

  1. Create a contact, set IM field to custom type "a b" with a username.
  2. Before fix: Export → 0-byte file, error toast.
  3. After fix: Export succeeds, IMPP line written as IMPP:a-b:username.

Compiled and linted against fossDebug variant — no errors or new warnings.

Note on round-trip fidelity

Labels with spaces will be stored as hyphen-separated strings in the exported VCF (e.g. "a b""a-b"). Preserving the original label through the URI scheme is not possible without a larger structural change (URI schemes forbid percent-encoding). This is a known limitation documented in the code comment.

Custom IM type labels are used as the URI scheme when building IMPP
properties (e.g. `a b:username`). URI schemes only allow the character
set [a-zA-Z][a-zA-Z0-9+-.]*; a label containing spaces or other
special characters caused ez-vcard's Impp constructor to throw an
IllegalArgumentException, which silently aborted the export and left
a 0-byte file on disk.

Fix: replace any character outside the valid URI-scheme set with a
hyphen before constructing the Impp object. Also guard against labels
that start with a non-letter (prefix "x-") or are empty ("x-custom").

Fixes FossifyOrg#499
@faraz152 faraz152 requested a review from naveensingh as a code owner April 22, 2026 08:31
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.

Space in IM type field breaks export

1 participant