After applying your patch, the issue is fixed, and the array is now dumped correctly without extra spaces. The patch looks good to me.
Regarding testing: for this case, a Perl test might actually be more suitable than SQL tests, because OIDs can change between runs and Perl tests allow for better control and normalization of such values.