Import of r39569 from trunk. From Bertrand and me: don't access character [-1] for empty strings.
Changed paths: