Backport of 5.2.2 string library

Fixed StackOverflowException