Uploaded files named with a space can't be viewed or downloaded properly

I have RT 5.0.3, Postgres, attachments stored in database, apache FPM with mod_proxy_fcgi. When I upload Screenshot.png in a comment using the web interface, I can see the screen shot inline when I load the page, and also download it. If I do the same with a file named Screen shot.png, the image link is broken, and trying to download the image instead loads the homepage/dashboard.

Looking into this in more detail, the HTML output on the ticket display for the non-working case uses src and href attributes of this form: Attachment/99999/7143/Screen%20Shot.png.

I tried attaching this image via email, and the inline display instead used a src in the form of Attachment/99999/7143, and this works. The download link’s href still uses the full file name, and this still fails. If I truncate the non-working URLs to just the attachment ID, then they work properly as well.

I think something is broken in the path router, since apparently these files are all being saved to the database properly. It’s just broken when the output URLs are attempted to be served by RT.