You’ve already used sanitize_title
once in you code. You need to use that in again, inside the wpse5742_author_link
function.
$link = str_replace( $author_nicename, sanitize_title($author_nickname), $link );
That should take care of the spaces. Another other option is to use urlencode
but sanitize_title
keeps things consistent.
I (minimally) tested your code with that change and it seems to work.