Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix setting properties with group assignment #523

Merged

Conversation

mstilkerich
Copy link
Contributor

Setting properties that are part of a group is broken since version 4.0.0. The Component::remove() method for the specific case of a property given by its name (as string) that includes a group prefix will throw an exception. However, I believe the exception is only intended for the usage of this function where the property to remove is given as an object reference, not as a string, where the given property/component is not a child of component the remove() method is called on.

Example code to trigger the exception:

<?php

use Sabre\VObject;
use Sabre\VObject\Component\VCard;
include_once dirname(__FILE__) . "/vendor/autoload.php";

$vcard = new VObject\Component\VCard([
        'VERSION' => '3.0',
        'item2.X-ABLabel' => "Foo", // triggers exception
]);

$vcard->{"item1.X-ABLabel"} = "SpecialLabel"; // also triggers exception

print $vcard->serialize();

The exception will be triggered for both the usage in the constructor as well as by a separate set operation.

@codecov
Copy link

codecov bot commented Nov 14, 2020

Codecov Report

Merging #523 (31c9187) into master (38bc2d2) will increase coverage by 0.04%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #523      +/-   ##
============================================
+ Coverage     98.69%   98.73%   +0.04%     
  Complexity     1759     1759              
============================================
  Files            66       66              
  Lines          4279     4279              
============================================
+ Hits           4223     4225       +2     
+ Misses           56       54       -2     
Impacted Files Coverage Δ Complexity Δ
lib/Component.php 99.55% <100.00%> (+0.88%) 92.00 <0.00> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 38bc2d2...31c9187. Read the comment docs.

Copy link
Member

@DeepDiver1975 DeepDiver1975 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for your contribution!

Can I ask you to add a unit test for this case? 👍

Copy link
Contributor

@phil-davis phil-davis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks reasonable. Just needs unit test(s) so this does not get broken again in future.

@phil-davis phil-davis self-requested a review November 17, 2020 10:55
@mstilkerich
Copy link
Contributor Author

Hello, I added a test case.

@mstilkerich
Copy link
Contributor Author

Hello, I added the requested test. Is there still a problem?

@phil-davis phil-davis force-pushed the fix_set_properties_with_groups branch from f5688f4 to 31c9187 Compare February 12, 2021 00:39
@phil-davis
Copy link
Contributor

With the new test case on master

There was 1 error:

1) Sabre\VObject\ComponentTest::testAddGroupProperties
InvalidArgumentException: The item you passed to remove() was not a child of this component

/home/phil/git/sabre-io/vobject/lib/Component.php:165
/home/phil/git/sabre-io/vobject/lib/Component.php:483
/home/phil/git/sabre-io/vobject/tests/VObject/ComponentTest.php:82

ERRORS!
Tests: 1721, Assertions: 2639, Errors: 1.
Script phpunit --configuration tests/phpunit.xml handling the phpunit event returned with error code 2

That's good, the test fails. And passes with the fix.

@phil-davis phil-davis dismissed DeepDiver1975’s stale review February 12, 2021 00:44

test has been added

@phil-davis phil-davis merged commit 7de7811 into sabre-io:master Feb 12, 2021
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.

3 participants