escape all head and tail occurences, update #2861