tinyxml2 icon indicating copy to clipboard operation
tinyxml2 copied to clipboard

Read the special numeric character such   or 中 ,the result is wrong?

Open zpczzf opened this issue 6 years ago • 2 comments

             if ( *(p+1) == '#' ) {
                    const int buflen = 10;
                    char buf[buflen] = { 0 };
                    int len = 0;
                    char* adjusted = const_cast<char*>( XMLUtil::GetCharacterRef( p, buf, &len ) );
                    if ( adjusted == 0 ) {
                        *q = *p;
                        ++p;
                        ++q;
                    }
                    else {
                        TIXMLASSERT( 0 <= len && len <= buflen );
                        TIXMLASSERT( q + len <= adjusted );
                        p = adjusted;
                        memcpy( q, buf, len );
                        q += len;
                    }
                }

zpczzf avatar Aug 28 '19 02:08 zpczzf

hi @zpczzf

Start again.

Please provide testcase which shows that TinyXML-2 indeed failing. Or concept.

Until it have been proved by you, this issue have no sense.

JulianVolodia avatar Sep 13 '19 12:09 JulianVolodia

Hi @leethomason I think you can close that issue as the StrPair::GetStr seems to work properly (as my unittests shows)

TEST(XmlStrPairTest, GetStrTest) {
    {
        char testString[] { "&#160;\0"};
        tinyxml2::StrPair strPair;
        strPair.Set(testString, testString+6, tinyxml2::StrPair::NEEDS_ENTITY_PROCESSING);
        const char* result = strPair.GetStr();
        EXPECT_EQ(testString[0], 0xc2);
        EXPECT_EQ(testString[1], 0xA0);
        EXPECT_EQ(testString[2], 0);
    }
    {
        char testString[] { "&#x4e2d;"};
        tinyxml2::StrPair strPair;
        strPair.Set(testString, testString+8, tinyxml2::StrPair::NEEDS_ENTITY_PROCESSING);
        const char* result = strPair.GetStr();
        EXPECT_EQ(testString[0], 0xe4);
        EXPECT_EQ(testString[1], 0xb8);
        EXPECT_EQ(testString[2], 0xad);
        EXPECT_EQ(testString[3], 0);
    }

}

khReichel avatar Jan 01 '22 11:01 khReichel