Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-105382

QLineEdit should not allow password undo/redo after switching back to QLineEdit::Normal

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Unresolved
    • Not Evaluated
    • None
    • 5.12, 6.3
    • None
    • All

    Description

      Currently, when QTextEdit::echoMode is set to something other than QTextEdit::Normal then undo/redo actions are disabled to prevent potentially exposing passwords.

      However, a common  GUI use case, is to provide a "reveal" button which temporarily sets QTextEdit::echoMode to Normal.  Currently, when switching to Normal, all of the undo/redo actions that were being blocked on the other echo modes are now suddenly available.

      I would like to suggest, then whenever QTextEdit::echoMode is is changed to Normal, from any of the other modes, the undo/redo buffer is reset.

      This could possibly be as easy as:

      --- qwidgetlinecontrol_p.h.old  2022-08-06 10:12:06.359833943 +1000
      +++ qwidgetlinecontrol_p.h.new  2022-08-06 10:19:01.382631373 +1000
      @@ -242,6 +242,10 @@
           uint echoMode() const { return m_echoMode; }
           void setEchoMode(uint mode)
           {
      +        // If switching from one of the hidden modes to Normal, clear the undo history.
      +        if ((mode == QLineEdit::Normal) && (m_echoMode != QLineEdit::Normal))
      +            clearUndo();
      +
               cancelPasswordEchoTimer();
               m_echoMode = mode;
               m_passwordEchoEditing = false;
      

      Note, the condition check is there because I reckon it makes sense to not clear the history if setting to {{Normal, when already Normal. The alternative would be an early no-op check, like this:

      --- qwidgetlinecontrol_p.h.old  2022-08-06 10:12:06.359833943 +1000
      +++ qwidgetlinecontrol_p.h.new  2022-08-06 10:22:05.320326582 +1000
      @@ -242,6 +242,8 @@
           uint echoMode() const { return m_echoMode; }
           void setEchoMode(uint mode)
           {
      +        if (m_echoMode == mode) return;
      +
               cancelPasswordEchoTimer();
               m_echoMode = mode;
               m_passwordEchoEditing = false;
      @@ -252,6 +254,10 @@
               if (m_echoMode != QLineEdit::Normal)
                   m_text.reserve(30);
       
      +        // If switching to a hide-echo mode, clear the undo history.
      +        if (m_echoMode == QLineEdit::Normal)
      +            clearUndo();
      +
               updateDisplayText();
           }
      

      But that could have unintended side-effects (callers relying on repeatedly setting the same mode have some other update effects).

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            paul Paul Colby
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes