Fixed trailing slash removal code.

Change-Id: I152dcec5cc8f4c417e3503f4b8fd3fdd8bc4fda5
(cherry picked from commit f8ba6474788b5382de8211909ef61564fc5c63ca)