Page MenuHomePhabricator

Do not allow changing labels to empty ones when PATCHing
Open, Needs TriagePublic

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