RFC109: fix inifinite loop on metadata substitutions (#4877)