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

QUrl::matches() behaves incorrect with QUrl::RemovePort, QUrl::RemoveUserInfo and QUrl::RemovePassword

    XMLWordPrintable

Details

    • caa598c843eb27fd0c645e62723fd2d4e3e12f60 (qt/qtbase/dev)

    Description

      QUrl::matches() behaves incorrect when using one of the formatting options QUrl::RemovePort, QUrl::RemoveUserInfo or QUrl::RemovePassword.

      For example, when using QUrl::RemovePort, the comparison of the host is disabled. This leads to the following expression unexpectedly returning true:

      QUrl("http://example.com").matches(QUrl("http://foobar.com"), QUrl::RemovePort)
      

      The reason is the incorrect checking of the formatting option flags in QUrl::matches():

      qurl.cpp, lines 3667-3670
          if (options & QUrl::RemoveUserInfo)
              mask &= ~QUrlPrivate::UserName;
          else if (d->userName != url.d->userName)
              return false;
      

      and

      qurl.cpp, lines 3677-3680
          if (options & QUrl::RemoveAuthority)
              mask &= ~QUrlPrivate::Host;
          else if (d->host != url.d->host)
              return false;
      

      It should probably look like this:

          if ( (options & QUrl::RemoveUserInfo) == QUrl::RemoveUserInfo)
              mask &= ~QUrlPrivate::UserName;
          else if (d->userName != url.d->userName)
              return false;
      

      and

          if ( (options & QUrl::RemoveAuthority) == QUrl::RemoveAuthority)
              mask &= ~QUrlPrivate::Host;
          else if (d->host != url.d->host)
              return false;
      

      See also QUrl::adjusted() where the checks are done like that.

      Attachments

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

        Activity

          People

            thiago Thiago Macieira
            ignitor Jochen Ulrich
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes