Just hash raw bytes. Treat it as data and set a maximum byte limit.
Even if you assume that a user has a broken setup that somehow submits weird characters, you're still better off accepting it so that at least they can continue to log in using that weird setup, as opposed to trying to "correct" it and potentially locking the user out.