Fixes #5703, prevent infinite loop on trailing slash.
Merge pull request #4138 from waldenraines/5703

Fixes #5703, prevent infinite loop on trailing slash.