trinity-devel@lists.pearsoncomputing.net

Message: previous - next
Month: March 2016

Re: [trinity-devel] Re: Re: Re: TQString::fromUtf8 vs TQString::fromLatin1 [possible bug in parseVCard]

From: Fat-Zer <fatzer2@...>
Date: Sun, 27 Mar 2016 17:09:13 +0300
2016-03-27 15:07 GMT+03:00 deloptes <deloptes@...>:
> Fat-Zer wrote:
>
>> 2016-03-26 11:42 GMT+03:00 deloptes
>> <deloptes@...>:
>>> Hi,
>>> this is also how I understand the ascii(), but do you have explanation
>>> how I then see the ��� (utf?). The above was just an experiment.
>>> For the code I wrote I solved the problem by passing the c_str() to
>>> parseVCard. This passes char array and does not care about the content
>>> that much (my understanding)
>>>
>>> regards
>>>
>> Yes, It seems you are right there is a bug, haven't tried myself, but
>> should do the trick:
>>
>> diff --git a/tdeabc/vcardparser/vcardparser.cpp
>> b/tdeabc/vcardparser/vcardparser.cpp
>> index 7ac07ce..db33263 100644
>> --- a/tdeabc/vcardparser/vcardparser.cpp
>> +++ b/tdeabc/vcardparser/vcardparser.cpp
>> @@ -152,7 +152,7 @@ VCard::List VCardParser::parseVCards( const TQString&
>> text )
>>              KCodecs::quotedPrintableDecode( input, output );
>>            }
>>          } else {
>> -          output = TQCString(value.latin1());
>> +          output = TQCString(value.utf8());
>>          }
>>
>>          if ( params.findIndex( "charset" ) != -1 ) { // have to
>> convert the data
>>
>> Note that VCardParser::parseVCards() is generally encoding-unsafe...
>>
>
> Yes I also looked into this, I closed the file less than 60sec later -
> because I started having headache.
> I don't understand what this diff means - do you mean how it should be or is
> it something from the history of the file?

Yes, it is how it should be, a fix for tdelibs. But note if vcard will
have a field in a different encoding (e.g. "charset" parameter is set)
the code will likely fail... To fix it completely the whole api
changes are required (pass TQByteArray to the parser rather than
TQString).

>>
>> PS, some notes about your code:
>>> std::string data_str(data.utf8(),data.utf8().length());
>>>        SE_LOG_DEBUG(getDisplayName(), "TDE addressbook ENTRY AFTER
>>>\n%s\n",data_str.c_str() );
>> Note that there is no need here to create here an intermediate
>> std::string, next code should work by itself:
>>
>> std::string data_str(data.utf8(),data.utf8().length());
>> SE_LOG_DEBUG(getDisplayName(), "TDE addressbook ENTRY
>> AFTER\n%s\n",data.utf8() );
>>
>> if not, just cast it to (const char *).
>>
>
> Thank you - you speak out some of my thoughts. I also think I have tested
> the above, but not sure anymore.
>
>>>TDEABC::Addressee addressee = converter.parseVCard(item.c_str());
>> This is an equivalent to fromLatin1(), so it will work only for your
>> locale...
>>
>
> I'm not sure if I understand this well. fromLatin1 means I use iso-8859, but
> I use utf8. It is also obvious that the input (item) is received in utf8. I
> had different experience when using TQString::fromLatin1 ()

Here you implicitly use QString (const char*) which is an equivalent
to QString::fromAscii (), which is equivalent of fromLatin1 () as far
as you don't set QTextCodec::codecForCStrings(). So the code will
likely fail if it will have some other encoding.

>> Next tim if you encounter such issues, try to provide a minimal
>> compiliable test example. That will significantly ease the testing and
>> understanding what's wrong...
>
> Yes, you are correct again, however time constrains and frustration
> prevented me doing this as I have to clean the test code from older tests,
> I commented out. I add now something, however I was disappointed that
> output of the test program was different to what I saw in the AddressBook.
> Perhaps because you have to convert the addressee back and this makes the
> original problem right somewhere in the converter.
>
> Find attached the code and compile like this
>
> PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/opt/trinity/lib/pkgconfig \
>         g++ `pkg-config --cflags tqt` -I/opt/trinity/include \
>             `pkg-config --libs tqt` -L/opt/trinity/lib \
>         -ltdecore -ltdeabc std-test.cc -o std-abreader
>
> To check the result in the address book you have to uncomment the write and
> save lines and also cleanup tdeabc lock and cache files prior to executing.
> I had a very bad experience with those already
>
> rm -f ~/.trinity/share/apps/tdeabc/lock/*.trinity_share_apps_tdeabc_std.vcf*
> \
>         ~/.trinity/share/apps/tdeabc/std.vcf__*
>
> regards
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: trinity-devel-unsubscribe@...
> For additional commands, e-mail: trinity-devel-help@...
> Read list messages on the web archive: http://trinity-devel.pearsoncomputing.net/
> Please remember not to top-post: http://trinity.pearsoncomputing.net/mailing_lists/#top-posting