Trim off whitespace when saving custom fields

3.0-unstable patch of #2386