How can i list a user's groups when their names contain spaces?

Although groups doesn't appear to have an option to null-delimit entries, id does - at least in the GNU CoreUtils implementation that should apply on Ubuntu 18.041

   -z, --zero
          delimit entries with NUL characters, not whitespace;

So for example

id -Gnz someuser

should give a null-delimited list of the names of someuser's supplementary groups - you can check that's the case using

id -Gnz someuser | xargs -0 printf '%s\n'

1 Note that POSIX doesn't mandate this option, so it won't be portable. See for example The Open Group Base Specifications