Update the CSS optimizer to end a URL path at a hash as well as a question mark

Fixes #17243

(cherry picked from commit cbe848ad3948f4a14ce8f0a1391d511370f6e07f)
(cherry picked from commit f725de13188853feafa7abe0fdbca8a9451e1a48)