Properly encode hash characters in the URL fragment (#12796)

GWT issue: 8396
Change-Id: If265752d30485b4b072763a2a4aad6deb40ea386