fix for 24051: modifying password field corrupts pw text; checked in on behalf of buster; r=jfrancis

git-svn-id: svn://10.0.0.236/trunk@59974 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
jfrancis%netscape.com 2000-02-07 02:48:36 +00:00
parent b831c35945
commit a8e66f4adc
5 changed files with 41 additions and 29 deletions

View File

@ -132,6 +132,7 @@ nsTextEditRules::SetFlags(PRUint32 aFlags)
mEditor->SetBodyWrapWidth(72);
}
}
mFlags = aFlags;
return NS_OK;
}
@ -519,7 +520,8 @@ nsTextEditRules::WillInsertText(PRInt32 aAction,
*aCancel = PR_FALSE;
*aHandled = PR_TRUE;
*aOutString = *aInString;
PRInt32 start=0; PRInt32 end=0;
// handle docs with a max length
res = TruncateInsertionIfNeeded(aSelection, aInString, aOutString, aMaxLength);
if (NS_FAILED(res)) return res;
@ -527,7 +529,8 @@ nsTextEditRules::WillInsertText(PRInt32 aAction,
// handle password field docs
if (mFlags & nsIHTMLEditor::eEditorPasswordMask)
{
res = EchoInsertionToPWBuff(aSelection, aOutString);
res = mEditor->GetTextSelectionOffsets(aSelection, start, end);
NS_ASSERTION((NS_SUCCEEDED(res)), "getTextSelectionOffsets failed!");
if (NS_FAILED(res)) return res;
}
@ -548,6 +551,15 @@ nsTextEditRules::WillInsertText(PRInt32 aAction,
// we want to ignore result of WillInsert()
*aCancel = PR_FALSE;
// handle password field data
// this has the side effect of changing all the characters in aOutString
// to the replacement character
if (mFlags & nsIHTMLEditor::eEditorPasswordMask)
{
res = EchoInsertionToPWBuff(start, end, aOutString);
if (NS_FAILED(res)) return res;
}
// if we're a single line control, pretreat the input string to remove returns
// this is unnecessary if we use <BR>'s for breaks in "plain text", because
// InsertBreak() checks the string. But we don't currently do that, so we need this
@ -1507,19 +1519,12 @@ nsTextEditRules::TruncateInsertionIfNeeded(nsIDOMSelection *aSelection,
nsresult
nsTextEditRules::EchoInsertionToPWBuff(nsIDOMSelection *aSelection, nsString *aOutString)
nsTextEditRules::EchoInsertionToPWBuff(PRInt32 aStart, PRInt32 aEnd, nsString *aOutString)
{
if (!aSelection || !aOutString) {return NS_ERROR_NULL_POINTER;}
if (!aOutString) {return NS_ERROR_NULL_POINTER;}
// manage the password buffer
PRInt32 start, end;
nsresult res = mEditor->GetTextSelectionOffsets(aSelection, start, end);
NS_ASSERTION((NS_SUCCEEDED(res)), "getTextSelectionOffsets failed!");
if (end!=start)
{
mPasswordText.Cut(start, end-start);
}
mPasswordText.Insert(*aOutString, start);
mPasswordText.Insert(*aOutString, aStart);
#ifdef DEBUG_jfrancis
char *password = mPasswordText.ToNewCString();
@ -1534,7 +1539,7 @@ nsTextEditRules::EchoInsertionToPWBuff(nsIDOMSelection *aSelection, nsString *aO
for (i=0; i<length; i++)
*aOutString += '*';
return res;
return NS_OK;
}

View File

@ -198,7 +198,7 @@ protected:
/** Echo's the insertion text into the password buffer, and converts
insertion text to '*'s */
nsresult EchoInsertionToPWBuff(nsIDOMSelection *aSelection, nsString *aOutString);
nsresult EchoInsertionToPWBuff(PRInt32 aStart, PRInt32 aEnd, nsString *aOutString);
/** do the actual text insertion */
nsresult DoTextInsertion(nsIDOMSelection *aSelection,

View File

@ -132,6 +132,7 @@ nsTextEditRules::SetFlags(PRUint32 aFlags)
mEditor->SetBodyWrapWidth(72);
}
}
mFlags = aFlags;
return NS_OK;
}
@ -519,7 +520,8 @@ nsTextEditRules::WillInsertText(PRInt32 aAction,
*aCancel = PR_FALSE;
*aHandled = PR_TRUE;
*aOutString = *aInString;
PRInt32 start=0; PRInt32 end=0;
// handle docs with a max length
res = TruncateInsertionIfNeeded(aSelection, aInString, aOutString, aMaxLength);
if (NS_FAILED(res)) return res;
@ -527,7 +529,8 @@ nsTextEditRules::WillInsertText(PRInt32 aAction,
// handle password field docs
if (mFlags & nsIHTMLEditor::eEditorPasswordMask)
{
res = EchoInsertionToPWBuff(aSelection, aOutString);
res = mEditor->GetTextSelectionOffsets(aSelection, start, end);
NS_ASSERTION((NS_SUCCEEDED(res)), "getTextSelectionOffsets failed!");
if (NS_FAILED(res)) return res;
}
@ -548,6 +551,15 @@ nsTextEditRules::WillInsertText(PRInt32 aAction,
// we want to ignore result of WillInsert()
*aCancel = PR_FALSE;
// handle password field data
// this has the side effect of changing all the characters in aOutString
// to the replacement character
if (mFlags & nsIHTMLEditor::eEditorPasswordMask)
{
res = EchoInsertionToPWBuff(start, end, aOutString);
if (NS_FAILED(res)) return res;
}
// if we're a single line control, pretreat the input string to remove returns
// this is unnecessary if we use <BR>'s for breaks in "plain text", because
// InsertBreak() checks the string. But we don't currently do that, so we need this
@ -1507,19 +1519,12 @@ nsTextEditRules::TruncateInsertionIfNeeded(nsIDOMSelection *aSelection,
nsresult
nsTextEditRules::EchoInsertionToPWBuff(nsIDOMSelection *aSelection, nsString *aOutString)
nsTextEditRules::EchoInsertionToPWBuff(PRInt32 aStart, PRInt32 aEnd, nsString *aOutString)
{
if (!aSelection || !aOutString) {return NS_ERROR_NULL_POINTER;}
if (!aOutString) {return NS_ERROR_NULL_POINTER;}
// manage the password buffer
PRInt32 start, end;
nsresult res = mEditor->GetTextSelectionOffsets(aSelection, start, end);
NS_ASSERTION((NS_SUCCEEDED(res)), "getTextSelectionOffsets failed!");
if (end!=start)
{
mPasswordText.Cut(start, end-start);
}
mPasswordText.Insert(*aOutString, start);
mPasswordText.Insert(*aOutString, aStart);
#ifdef DEBUG_jfrancis
char *password = mPasswordText.ToNewCString();
@ -1534,7 +1539,7 @@ nsTextEditRules::EchoInsertionToPWBuff(nsIDOMSelection *aSelection, nsString *aO
for (i=0; i<length; i++)
*aOutString += '*';
return res;
return NS_OK;
}

View File

@ -198,7 +198,7 @@ protected:
/** Echo's the insertion text into the password buffer, and converts
insertion text to '*'s */
nsresult EchoInsertionToPWBuff(nsIDOMSelection *aSelection, nsString *aOutString);
nsresult EchoInsertionToPWBuff(PRInt32 aStart, PRInt32 aEnd, nsString *aOutString);
/** do the actual text insertion */
nsresult DoTextInsertion(nsIDOMSelection *aSelection,

View File

@ -2863,7 +2863,9 @@ nsGfxTextControlFrame::InitializeTextControl(nsIPresShell *aPresShell, nsIDOMDoc
}
// finish initializing editor
mEditor->EnableUndo(PR_TRUE);
// turn in undo, *except* for password fields.
if (!IsPasswordTextControl())
mEditor->EnableUndo(PR_TRUE);
// set readonly and disabled states
if (mContent)