Fixes #17053.  Delay escaping special characters so that character counts are accurate.  Added automated test.