Skip to content

Fix AbstractRdapService::remove() deleting the wrong array element - #9

Open
tomsommer wants to merge 1 commit into
ArrayAccess:mainfrom
tomsommer:fix-service-remove
Open

tomsommer wants to merge 1 commit into
ArrayAccess:mainfrom
tomsommer:fix-service-remove

Conversation

@tomsommer

Copy link
Copy Markdown

AbstractRdapService::remove() looked up the definition in the service's targets list ($service[0]), but then used that offset to unset an element of the service tuple itself ($this->services[$key][$offset]). Removing one target therefore dropped the whole targets list (offset 0) or the URL list (offset 1) of that service:

$service = new DomainService('1.0', 'test', '2024-01-01T00:00:00Z', [
    [['com', 'net'], ['https://rdap.example/com/']],
]);
$service->remove('com');

// before: [[["https://rdap.example/com/"]]]          ('net' lost, URL list moved into the targets slot)
// after:  [[["net"], ["https://rdap.example/com/"]]]

Now the target is removed from the targets list, the service entry is dropped once it has no targets left, and the services list is re-indexed.

phpcs and phpstan pass.

The offset of the definition in the targets list was used to unset an
element of the service tuple itself, so removing one target dropped
the whole targets list (or the URL list) of that service. Remove the
target from the targets list and drop the service once it has none.
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.

1 participant