StyledText: fix reading of utf-8 documents
BNode::ReadAttrString does not check for the attribute to actually be a string. It will return B_OK (and useless data) if called on a B_INT32_TYPE attribute. Check the attribute type before reading. Also remove various debug ouput leftovers. May fix #12976.
This commit is contained in:
@@ -524,16 +524,19 @@ translate_from_text(BPositionIO* source, const char* encoding, bool forceEncodin
|
||||
BMallocIO encodingIO;
|
||||
|
||||
BNode* node = dynamic_cast<BNode*>(source);
|
||||
BString name(encoding);
|
||||
if (node != NULL) {
|
||||
// determine encoding, if available
|
||||
bool hasAttribute = false;
|
||||
if (encoding != NULL && !forceEncoding) {
|
||||
BString name;
|
||||
if ((node->ReadAttrString("be:encoding", &name) == B_OK)
|
||||
&& (name.Length() > 0)) {
|
||||
attr_info info;
|
||||
node->GetAttrInfo("be:encoding", &info);
|
||||
|
||||
if ((info.type == B_STRING_TYPE) && (node->ReadAttrString(
|
||||
"be:encoding", &name) == B_OK)) {
|
||||
encoding = name.String();
|
||||
hasAttribute = true;
|
||||
} else {
|
||||
} else if (info.type == B_INT32_TYPE) {
|
||||
// Try the BeOS version of the atribute, which used an int32
|
||||
// and a well-known list of encodings.
|
||||
int32 value;
|
||||
@@ -542,8 +545,8 @@ translate_from_text(BPositionIO* source, const char* encoding, bool forceEncodin
|
||||
if (bytesRead == (ssize_t)sizeof(value)) {
|
||||
hasAttribute = true;
|
||||
if (value != 65535) {
|
||||
const BCharacterSet* characterSet = NULL;
|
||||
characterSet = BCharacterSetRoster::GetCharacterSetByConversionID(value);
|
||||
const BCharacterSet* characterSet
|
||||
= BCharacterSetRoster::GetCharacterSetByConversionID(value);
|
||||
if (characterSet != NULL)
|
||||
encoding = characterSet->GetName();
|
||||
}
|
||||
@@ -603,7 +606,6 @@ translate_from_text(BPositionIO* source, const char* encoding, bool forceEncodin
|
||||
status = codec.Decode(pos, bytes,
|
||||
(char*)encodingBuffer.Buffer(), encodingLength);
|
||||
if (status < B_OK) {
|
||||
puts("oops");
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
@@ -141,7 +141,6 @@ StyledEditApp::StyledEditApp()
|
||||
sWindowRect.top *= factor;
|
||||
sWindowRect.right *= factor;
|
||||
sWindowRect.bottom *= factor;
|
||||
sWindowRect.PrintToStream();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -87,10 +87,6 @@ BTextEncoding::Decode(const char* input, size_t& inputLength, char* output,
|
||||
ucnv_convertEx(fUtf8Converter, fConverter, &target, output + outputLength,
|
||||
&base, input + inputLength, NULL, NULL, NULL, NULL, FALSE, TRUE,
|
||||
&error);
|
||||
if (!U_SUCCESS(error)) {
|
||||
printf("zz %s\n", u_errorName(error));
|
||||
}
|
||||
|
||||
|
||||
// inputLength is set to the number of bytes consumed. We may not use all of
|
||||
// the input data (for example if it is cut in the middle of an utf-8 char).
|
||||
|
||||
Reference in New Issue
Block a user