Back porting some tests fixes
Fixed error with surrogate pairs and locations lengths
Fixed IO tests and possible BOM ambiguities

issue #580