Bug 228270 - Fix problem where UTF8 sequences in the password file were being re-encoded as UTF8 (as if from UTF16) when the password file is read in. r=darin, sr=bzbarsky

This commit is contained in:
bryner%brianryner.com 2004-01-18 23:51:27 +00:00
Родитель ac85253d6a
Коммит b43b1ea6a9
1 изменённых файлов: 16 добавлений и 8 удалений

Просмотреть файл

@ -1333,6 +1333,7 @@ nsPasswordManager::ReadSignonFile()
// Read the header
nsAutoString buffer;
nsCAutoString utf8Buffer;
PRBool moreData = PR_FALSE;
nsresult rv = lineStream->ReadLine(buffer, &moreData);
if (NS_FAILED(rv))
@ -1354,17 +1355,23 @@ nsPasswordManager::ReadSignonFile()
if (NS_FAILED(rv))
return;
// |buffer| will contain UTF-8 encoded characters, so move it into
// a narrow string so we can manipulate it. If NS_ReadLine is ever
// fixed to handle character encoding, this code should be cleaned up.
utf8Buffer.AssignWithConversion(buffer);
switch (state) {
case STATE_REJECT:
if (buffer.Equals(NS_LITERAL_STRING(".")))
if (utf8Buffer.Equals(NS_LITERAL_CSTRING(".")))
state = STATE_REALM;
else
mRejectTable.Put(NS_ConvertUCS2toUTF8(buffer), 1);
mRejectTable.Put(utf8Buffer, 1);
break;
case STATE_REALM:
realm.Assign(NS_ConvertUCS2toUTF8(buffer));
realm.Assign(utf8Buffer);
state = STATE_USERFIELD;
break;
@ -1375,12 +1382,12 @@ nsPasswordManager::ReadSignonFile()
AddSignonData(realm, entry);
// If the line is a ., we've reached the end of this realm's entries.
if (buffer.Equals(NS_LITERAL_STRING("."))) {
if (utf8Buffer.Equals(NS_LITERAL_CSTRING("."))) {
entry = nsnull;
state = STATE_REALM;
} else {
entry = new SignonDataEntry();
entry->userField.Assign(buffer);
CopyUTF8toUTF16(utf8Buffer, entry->userField);
state = STATE_USERVALUE;
}
@ -1389,7 +1396,7 @@ nsPasswordManager::ReadSignonFile()
case STATE_USERVALUE:
NS_ASSERTION(entry, "bad state");
entry->userValue.Assign(buffer);
CopyUTF8toUTF16(utf8Buffer, entry->userValue);
state = STATE_PASSFIELD;
break;
@ -1398,7 +1405,8 @@ nsPasswordManager::ReadSignonFile()
NS_ASSERTION(entry, "bad state");
// Strip off the leading "*" character
entry->passField.Assign(Substring(buffer, 1, buffer.Length() - 1));
CopyUTF8toUTF16(Substring(utf8Buffer, 1, utf8Buffer.Length() - 1),
entry->passField);
state = STATE_PASSVALUE;
break;
@ -1406,7 +1414,7 @@ nsPasswordManager::ReadSignonFile()
case STATE_PASSVALUE:
NS_ASSERTION(entry, "bad state");
entry->passValue.Assign(buffer);
CopyUTF8toUTF16(utf8Buffer, entry->passValue);
state = STATE_USERFIELD;
break;