#1123266 patch by Dave Reid: fixed replacing empty token replacements