https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=236204 doesn't allow a comma-separated list to be used in the login class capabilities; in particular, for setenv, a comma-separated list of domains was given, and broken up inappropriately.
This is an admittedly-simplistic attempt to fix that; it doesn't depend on the documented escaping methods, but instead, treats a string (as defined by single and double quotes) as already-escaped, and simply looks for the end of the quoted part before doing any further processing.