Index: src/OFMutableString.m ================================================================== --- src/OFMutableString.m +++ src/OFMutableString.m @@ -135,10 +135,15 @@ size_t len; [self freeMemory: string]; len = strlen(str); + + if (len >= 3 && !memcmp(str, "\xEF\xBB\xBF", 3)) { + str += 3; + len -= 3; + } switch (of_string_check_utf8(str, len)) { case 0: isUTF8 = NO; break; @@ -161,10 +166,15 @@ - (void)appendCString: (const char*)str { size_t strlength; strlength = strlen(str); + + if (strlength >= 3 && !memcmp(str, "\xEF\xBB\xBF", 3)) { + str += 3; + strlength -= 3; + } switch (of_string_check_utf8(str, strlength)) { case 1: isUTF8 = YES; break; @@ -179,10 +189,15 @@ } - (void)appendCString: (const char*)str withLength: (size_t)len { + if (len >= 3 && !memcmp(str, "\xEF\xBB\xBF", 3)) { + str += 3; + len -= 3; + } + switch (of_string_check_utf8(str, len)) { case 1: isUTF8 = YES; break; case -1: Index: tests/OFStringTests.m ================================================================== --- tests/OFStringTests.m +++ tests/OFStringTests.m @@ -135,12 +135,12 @@ @"file://testfile.txt"] encoding: OF_STRING_ENCODING_ISO_8859_1]) && [s[1] isEqual: @"testäöü"]) TEST(@"-[appendCStringWithLength:]", - R([s[0] appendCString: "foobarqux" + 3 - withLength: 3]) && [s[0] isEqual: @"foobar"]) + R([s[0] appendCString: "foo\xEF\xBB\xBF" "barqux" + 3 + withLength: 6]) && [s[0] isEqual: @"foobar"]) EXPECT_EXCEPTION(@"Detection of invalid UTF-8 encoding #1", OFInvalidEncodingException, [OFString stringWithCString: "\xE0\x80"]) EXPECT_EXCEPTION(@"Detection of invalid UTF-8 encoding #2",