Does this result in there being a space before each comma?  You could fix this by using {%- and -%} in your if statement to get rid of the extra whitespace between the tag name and the comma.