Contacts import aborts with TypeError when vCards have no UID (TextImporter structure)

オープン 初心者向け
#66,486 コメント 2 件 リアクション 2 件 担当者 1 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@SebastianKrupinski がすでに取り組んでいます。

2026年11月10日 から。

  • #66489 @lazerg による — オープン
  • #66512 @SebastianKrupinski による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
72/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
php
領域
backend

調査の方向性

apps/dav/lib/CardDAV/Import/TextImporter.php の analyze() から始めます。ここでは UID のないコンポーネントがリストではなく素のインスタンスとして保存されています。次に、75 行目付近の ImportService::importText() を確認します。これは $instances[0] を読み取ります。修正は、UID のないエントリをリストでラップすることであり、同じパターンを apps/dav/lib/CalDAV/Import/TextImporter.php でも確認する必要があります。UID のない vCard が正常にインポートされることを、apps/dav のインポートテストで検証できたら完了です。

索引モデルが issue の本文から書いたものです。

説明

bug
Bug description

Importing a .vcf file in the Contacts app ("Import contacts") fails completely ("0 of 629 imported") when the vCards have no UID property. A Google Contacts export is the typical case: none of its 629 cards had a UID.

The server log shows:

TypeError: OCA\DAV\CardDAV\Import\TextImporter::extract(): Argument #1 ($start) must be of type int, string given,
called in apps/dav/lib/CardDAV/Import/ImportService.php on line 75

(request: /ocs/v2.php/contacts/import)

Cause

In apps/dav/lib/CardDAV/Import/TextImporter.php::analyze(), a component with a UID is stored as a list of instances:

$this->structure[$componentType][$componentId][] = [$componentType, $componentId, $componentStart, $componentEnd];

A component without a UID is stored as a bare instance, not wrapped in a list:

$this->structure[$componentType][] = [$componentType, $componentId, $componentStart, $componentEnd];

ImportService::importText() expects a list of instances in both cases:

foreach ($structure['VCARD'] as $cid => $instances) {
    $instance = $instances[0];                                   // "VCARD" (string) for UID-less cards
    $sObjectContents = $importer->extract($instance[2], $instance[3]);  // "A", "R" -> TypeError

The generator throws on the first UID-less card, so the whole import is aborted.

The same pattern exists in apps/dav/lib/CalDAV/Import/TextImporter.php. There, ImportService casts the values with (int), so it does not throw, but it would read wrong byte ranges.

Steps to reproduce
  1. Create test.vcf:
    BEGIN:VCARD
    VERSION:3.0
    FN:Erika Mustermann
    N:Mustermann;Erika;;;
    TEL;TYPE=CELL:+49 170 0000000
    END:VCARD
    
  2. Contacts → Contacts settings → Import contacts → choose test.vcf.
  3. Result: "0 of 1 imported", with the TypeError above in nextcloud.log.

Adding a UID: line to each card makes the import succeed. I verified this with the original file: all 629 cards imported.

Expected behavior

vCards without a UID are imported. A UID is optional in vCard 3.0, and the CardDAV backend can generate one.

Suggested fix

Wrap the UID-less entry in a list as well, for example:

$this->structure[$componentType][] = [[$componentType, $componentId, $componentStart, $componentEnd]];

The same applies to the CalDAV TextImporter.

Versions
  • Nextcloud 35.0.2 (Docker image nextcloud:35-apache), PHP 8.5.12, MariaDB 11.4
  • Contacts app 8.9.5
  • The same code is in master, stable35 and stable34 as of today.
主要言語
PHP
スター
37.5k
フォーク
5.4k
平均マージ
1日 14時間
マージ済み PR(30日)
648

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

nextcloud/server のほかの issue

nextcloud/server の issue をすべて見る

似ている issue

PHP の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。