This fixes #4691.  It now trims the spaces from the ends, but not the middle.