Page MenuHomePhabricator

Do not allow changing labels to empty ones when PATCHing
Closed, ResolvedPublic2 Estimated Story Points

Description

PATCH /entities/items/{item_id}/labels route correctly forbids to change a label to an empty string (which some Wikibase logic interprets as an instruction to remove the label) -- see T332739.

However, if provided an input that is just whitespace, the API ends up passing the empty label further down, resulting in removal.
This seems to be caused by the fact the input label "value" has leading and trailing spaces "trimmed". Checking for emptiness possibly happens prior to the "trimming" operation.

Example JSON Patch

{
  "op": "replace",
  "path": "/en",
  "value": " "
}

It seems the PUT /entities/items/{item_id}/labels/{lang_code} correctly rejects the "only whitespace" input

Event Timeline

Change 923331 had a related patch set uploaded (by WMDE-leszek; author: WMDE-leszek):

[mediawiki/extensions/Wikibase@master] REST: Added a failing e2e test for missed edge cases PATCH labels

https://gerrit.wikimedia.org/r/923331

WMDE-leszek set the point value for this task to 2.May 30 2023, 9:58 AM

Change 923331 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] REST: Prevent patching a whitespace-only label

https://gerrit.wikimedia.org/r/923331