Added URI escaping to length calculation