conditionalize setting charset on whether it has a valid value