We should emit the charset restoration only if we have emitted its
setting in the header. As the condition was slightly different in both
cases it was possible that only one part of these two was emitted in
past.
Fixes#12074
Signed-off-by: Michal Čihař <michal@cihar.com>