fix escaping of characters in substitution variables, fixes #17286

See https://bugs.dojotoolkit.org/ticket/17286