fix NULL deref when the script encoding wasn't previously set