When data value normalization is enabled, most API modules that edit data values return the normalized version (what was actually saved), but wbsetclaim and wbsetreference don’t.
Original report:
With data value normalization enabled (T251480, currently on Test Wikidata), if you save a commonsMedia value with underscores (e.g. Douglas_adams_portrait_cropped.jpg), it will be saved with spaces (normalized), but if start to edit the statement again without reloading the page, you’ll still see the unnormalized version (with underscores). The UI should use the normalized value returned by the API.