STXTTranslator: Fix truncated "be:encoding" attribute write.
Same issue as the mail_util fix. Also while I'm here, alter behavior so that the Be-style attribute gets overwritten with the Haiku-style one, instead of getting left as is. Should potentially help with #14674.
This commit is contained in:
@@ -474,7 +474,7 @@ output_styles(BPositionIO *outDestination, uint32 text_size,
|
||||
styled text in outDestination
|
||||
*/
|
||||
status_t
|
||||
translate_from_text(BPositionIO* source, const char* encoding, bool forceEncoding,
|
||||
translate_from_text(BPositionIO* source, const char* outEncoding, bool forceEncoding,
|
||||
BPositionIO* destination, uint32 outType)
|
||||
{
|
||||
if (outType != B_TRANSLATOR_TEXT && outType != B_STYLED_TEXT_FORMAT)
|
||||
@@ -524,17 +524,16 @@ translate_from_text(BPositionIO* source, const char* encoding, bool forceEncodin
|
||||
BMallocIO encodingIO;
|
||||
|
||||
BNode* node = dynamic_cast<BNode*>(source);
|
||||
BString name(encoding);
|
||||
BString encoding(outEncoding);
|
||||
if (node != NULL) {
|
||||
// determine encoding, if available
|
||||
bool hasAttribute = false;
|
||||
if (encoding != NULL && !forceEncoding) {
|
||||
if (encoding.String() && !forceEncoding) {
|
||||
attr_info info;
|
||||
node->GetAttrInfo("be:encoding", &info);
|
||||
|
||||
if ((info.type == B_STRING_TYPE) && (node->ReadAttrString(
|
||||
"be:encoding", &name) == B_OK)) {
|
||||
encoding = name.String();
|
||||
"be:encoding", &encoding) == B_OK)) {
|
||||
hasAttribute = true;
|
||||
} else if (info.type == B_INT32_TYPE) {
|
||||
// Try the BeOS version of the atribute, which used an int32
|
||||
@@ -543,7 +542,6 @@ translate_from_text(BPositionIO* source, const char* encoding, bool forceEncodin
|
||||
ssize_t bytesRead = node->ReadAttr("be:encoding", B_INT32_TYPE, 0,
|
||||
&value, sizeof(value));
|
||||
if (bytesRead == (ssize_t)sizeof(value)) {
|
||||
hasAttribute = true;
|
||||
if (value != 65535) {
|
||||
const BCharacterSet* characterSet
|
||||
= BCharacterSetRoster::GetCharacterSetByConversionID(value);
|
||||
@@ -557,21 +555,20 @@ translate_from_text(BPositionIO* source, const char* encoding, bool forceEncodin
|
||||
// we don't write the encoding in this case
|
||||
}
|
||||
|
||||
if (encoding != NULL)
|
||||
if (!encoding.IsEmpty())
|
||||
encodingBuffer.Allocate(READ_BUFFER_SIZE * 4);
|
||||
|
||||
if (!hasAttribute && encoding != NULL) {
|
||||
if (!hasAttribute && !encoding.IsEmpty()) {
|
||||
// add encoding attribute, so that someone opening the file can
|
||||
// retrieve it for persistance
|
||||
node->WriteAttr("be:encoding", B_STRING_TYPE, 0, encoding,
|
||||
strlen(encoding));
|
||||
node->WriteAttrString("be:encoding", &encoding);
|
||||
}
|
||||
}
|
||||
|
||||
off_t outputSize = 0;
|
||||
ssize_t bytesRead;
|
||||
|
||||
BPrivate::BTextEncoding codec(encoding);
|
||||
BPrivate::BTextEncoding codec(encoding.String());
|
||||
|
||||
// output the actual text part of the data
|
||||
do {
|
||||
|
||||
Reference in New Issue
Block a user