Trim whitespace from input and prevent foreach warning in profiles

@andizer or @jdevalk please review.