Refine handling of null and empty URI fragments (#12207)

Change-Id: Ie133694b010a586c6336e9b04be7bcd94d2525e9