Fixed #874: Bug - Substitution replacement not terminated