Backport #8701, do not append a second slash with `trailing_slash: true`

Backport of #8701 to fix #8700