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

Đang mở Phù hợp với người mới
#66,486 2 bình luận 2 reaction 1 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@SebastianKrupinski đang làm issue này rồi.

Từ ngày 10/11/2026.

  • #66489 của @lazerg — đang mở
  • #66512 của @SebastianKrupinski — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
72/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
php
Lĩnh vực
backend

Hướng nghiên cứu

Bắt đầu trong apps/dav/lib/CardDAV/Import/TextImporter.php, trong analyze(), nơi các component không có UID được lưu dưới dạng instance trần thay vì danh sách. Sau đó kiểm tra ImportService::importText() quanh dòng 75, chỗ đọc $instances[0]. Cách sửa là bọc mục không có UID trong một danh sách, và cùng kiểu mẫu đó cần được kiểm tra trong apps/dav/lib/CalDAV/Import/TextImporter.php. Hoàn tất khi một vCard không có UID được import thành công, xác minh bằng một test trong các test import của apps/dav.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.
Ngôn ngữ chính
PHP
Star
37.5k
Fork
5.4k
Merge trung bình
1 ngày 14 giờ
Pull request đã merge (30 ngày)
648

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của nextcloud/server

Tất cả issue của nextcloud/server

Issue tương tự

Thêm issue về PHP

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.