#!perl
use Cassandane::Tiny;

sub test_card_get_adr_bogus_jscomp
    :needs_component_jmap
    ($self)
{
    my $jmap = $self->{jmap};
    my $carddav = $self->{carddav};

    xlog $self, "PUT vCard with bogus JSCOMPS parameters";
    # adr1: JSCOMPS references an empty component
    # adr2: JSCOMPS references a component that is not part of the address
    my $card = <<~"EOF";
    BEGIN:VCARD
    VERSION:4.0
    UID:bed2b3d9-479c-4800-84f5-04116c35fa0a
    PRODID:-//FOO//bar//EN
    FN:Test
    ADR;PROP-ID=adr1;JSCOMPS=";3;0":;;;foo;;;
    ADR;PROP-ID=adr2;JSCOMPS=";18;3":;;;foo;;;;;;;;;;;;;;;bar
    CREATED:20260625T000859Z
    END:VCARD
    EOF
    $card =~ s/\r?\n/\r\n/gs;

    $carddav->Request('PUT', 'Default/test.vcf',
        $card, 'Content-Type' => 'text/vcard');


    # Assert that the bogus JSCOMPS parameters are ignored.
    my $res = $jmap->request([
        ['ContactCard/get', { }, 'R1'],
    ]);

    my $jscard = $res->single_sentence('ContactCard/get')->arguments->{list}[0];

    $self->assert_cmp_deeply({
        adr1 => { components => [ { kind => 'locality', value => 'foo' } ] },
        adr2 => { components => [ { kind => 'locality', value => 'foo' } ] },
    }, $jscard->{addresses});
}
