Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qurl.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// Copyright (C) 2016 Intel Corporation.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
396#include "qurl.h"
397#include "qurl_p.h"
398#include "qplatformdefs.h"
399#include "qstring.h"
400#include "qstringlist.h"
401#include "qdebug.h"
402#include "qhash.h"
403#include "qdatastream.h"
404#include "private/qipaddress_p.h"
405#include "qurlquery.h"
406#include "private/qdir_p.h"
407#include <private/qtools_p.h>
408
410
411using namespace Qt::StringLiterals;
412using namespace QtMiscUtils;
413
414inline static bool isHex(char c)
415{
416 c |= 0x20;
417 return isAsciiDigit(c) || (c >= 'a' && c <= 'f');
418}
419
420static inline QString ftpScheme()
421{
422 return QStringLiteral("ftp");
423}
424
425static inline QString fileScheme()
426{
427 return QStringLiteral("file");
428}
429
430static inline QString webDavScheme()
431{
432 return QStringLiteral("webdavs");
433}
434
435static inline QString webDavSslTag()
436{
437 return QStringLiteral("@SSL");
438}
439
441{
442public:
443 enum Section : uchar {
444 Scheme = 0x01,
445 UserName = 0x02,
446 Password = 0x04,
448 Host = 0x08,
449 Port = 0x10,
451 Path = 0x20,
453 Query = 0x40,
454 Fragment = 0x80,
455 FullUrl = 0xff
456 };
457
458 enum Flags : uchar {
459 IsLocalFile = 0x01
460 };
461
463 // the high byte of the error code matches the Section
464 // the first item in each value must be the generic "Invalid xxx Error"
466
468
470
477
480
482
484
486
487 // the following three cases are only possible in combination with
488 // presence/absence of the path, authority and scheme. See validityError().
492
493 NoError = 0
494 };
495
501
502 QUrlPrivate();
505
506 void parse(const QString &url, QUrl::ParsingMode parsingMode);
507 bool isEmpty() const
508 { return sectionIsPresent == 0 && port == -1 && path.isEmpty(); }
509
510 std::unique_ptr<Error> cloneError() const;
511 void clearError();
512 void setError(ErrorCode errorCode, const QString &source, qsizetype supplement = -1);
513 ErrorCode validityError(QString *source = nullptr, qsizetype *position = nullptr) const;
516 { return validateComponent(section, input, 0, input.size()); }
517
518 // no QString scheme() const;
519 void appendAuthority(QString &appendTo, QUrl::FormattingOptions options, Section appendingTo) const;
520 void appendUserInfo(QString &appendTo, QUrl::FormattingOptions options, Section appendingTo) const;
521 void appendUserName(QString &appendTo, QUrl::FormattingOptions options) const;
522 void appendPassword(QString &appendTo, QUrl::FormattingOptions options) const;
523 void appendHost(QString &appendTo, QUrl::FormattingOptions options) const;
524 void appendPath(QString &appendTo, QUrl::FormattingOptions options, Section appendingTo) const;
525 void appendQuery(QString &appendTo, QUrl::FormattingOptions options, Section appendingTo) const;
526 void appendFragment(QString &appendTo, QUrl::FormattingOptions options, Section appendingTo) const;
527
528 // the "end" parameters are like STL iterators: they point to one past the last valid element
529 bool setScheme(const QString &value, qsizetype len, bool doSetError);
531 void setUserInfo(const QString &userInfo, qsizetype from, qsizetype end);
532 void setUserName(const QString &value, qsizetype from, qsizetype end);
533 void setPassword(const QString &value, qsizetype from, qsizetype end);
535 void setPath(const QString &value, qsizetype from, qsizetype end);
536 void setQuery(const QString &value, qsizetype from, qsizetype end);
537 void setFragment(const QString &value, qsizetype from, qsizetype end);
538
539 inline bool hasScheme() const { return sectionIsPresent & Scheme; }
540 inline bool hasAuthority() const { return sectionIsPresent & Authority; }
541 inline bool hasUserInfo() const { return sectionIsPresent & UserInfo; }
542 inline bool hasUserName() const { return sectionIsPresent & UserName; }
543 inline bool hasPassword() const { return sectionIsPresent & Password; }
544 inline bool hasHost() const { return sectionIsPresent & Host; }
545 inline bool hasPort() const { return port != -1; }
546 inline bool hasPath() const { return !path.isEmpty(); }
547 inline bool hasQuery() const { return sectionIsPresent & Query; }
548 inline bool hasFragment() const { return sectionIsPresent & Fragment; }
549
550 inline bool isLocalFile() const { return flags & IsLocalFile; }
552
553 QString mergePaths(const QString &relativePath) const;
554
556 int port;
557
565
566 std::unique_ptr<Error> error;
567
568 // not used for:
569 // - Port (port == -1 means absence)
570 // - Path (there's no path delimiter, so we optimize its use out of existence)
571 // Schemes are never supposed to be empty, but we keep the flag anyway
574
575 // 32-bit: 2 bytes tail padding available
576 // 64-bit: 6 bytes tail padding available
577};
578
580 : ref(1), port(-1),
581 sectionIsPresent(0),
582 flags(0)
583{
584}
585
587 : ref(1), port(copy.port),
588 scheme(copy.scheme),
589 userName(copy.userName),
590 password(copy.password),
591 host(copy.host),
592 path(copy.path),
594 fragment(copy.fragment),
595 error(copy.cloneError()),
596 sectionIsPresent(copy.sectionIsPresent),
598{
599}
600
602 = default;
603
604std::unique_ptr<QUrlPrivate::Error> QUrlPrivate::cloneError() const
605{
606 return error ? std::make_unique<Error>(*error) : nullptr;
607}
608
610{
611 error.reset();
612}
613
614inline void QUrlPrivate::setError(ErrorCode errorCode, const QString &source, qsizetype supplement)
615{
616 if (error) {
617 // don't overwrite an error set in a previous section during parsing
618 return;
619 }
620 error = std::make_unique<Error>();
621 error->code = errorCode;
622 error->source = source;
623 error->position = supplement;
624}
625
626// From RFC 3986, Appendix A Collected ABNF for URI
627// URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
628//[...]
629// scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
630//
631// authority = [ userinfo "@" ] host [ ":" port ]
632// userinfo = *( unreserved / pct-encoded / sub-delims / ":" )
633// host = IP-literal / IPv4address / reg-name
634// port = *DIGIT
635//[...]
636// reg-name = *( unreserved / pct-encoded / sub-delims )
637//[..]
638// pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
639//
640// query = *( pchar / "/" / "?" )
641//
642// fragment = *( pchar / "/" / "?" )
643//
644// pct-encoded = "%" HEXDIG HEXDIG
645//
646// unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
647// reserved = gen-delims / sub-delims
648// gen-delims = ":" / "/" / "?" / "#" / "[" / "]" / "@"
649// sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
650// / "*" / "+" / "," / ";" / "="
651// the path component has a complex ABNF that basically boils down to
652// slash-separated segments of "pchar"
653
654// The above is the strict definition of the URL components and we mostly
655// adhere to it, with few exceptions. QUrl obeys the following behavior:
656// - percent-encoding sequences always use uppercase HEXDIG;
657// - unreserved characters are *always* decoded, no exceptions;
658// - the space character and bytes with the high bit set are controlled by
659// the EncodeSpaces and EncodeUnicode bits;
660// - control characters, the percent sign itself, and bytes with the high
661// bit set that don't form valid UTF-8 sequences are always encoded,
662// except in FullyDecoded mode;
663// - sub-delims are always left alone, except in FullyDecoded mode;
664// - gen-delim change behavior depending on which section of the URL (or
665// the entire URL) we're looking at; see below;
666// - characters not mentioned above, like "<", and ">", are usually
667// decoded in individual sections of the URL, but encoded when the full
668// URL is put together (we can change on subjective definition of
669// "pretty").
670//
671// The behavior for the delimiters bears some explanation. The spec says in
672// section 2.2:
673// URIs that differ in the replacement of a reserved character with its
674// corresponding percent-encoded octet are not equivalent.
675// (note: QUrl API mistakenly uses the "reserved" term, so we will refer to
676// them here as "delimiters").
677//
678// For that reason, we cannot encode delimiters found in decoded form and we
679// cannot decode the ones found in encoded form if that would change the
680// interpretation. Conversely, we *can* perform the transformation if it would
681// not change the interpretation. From the last component of a URL to the first,
682// here are the gen-delims we can unambiguously transform when the field is
683// taken in isolation:
684// - fragment: none, since it's the last
685// - query: "#" is unambiguous
686// - path: "#" and "?" are unambiguous
687// - host: completely special but never ambiguous, see setHost() below.
688// - password: the "#", "?", "/", "[", "]" and "@" characters are unambiguous
689// - username: the "#", "?", "/", "[", "]", "@", and ":" characters are unambiguous
690// - scheme: doesn't accept any delimiter, see setScheme() below.
691//
692// Internally, QUrl stores each component in the format that corresponds to the
693// default mode (PrettyDecoded). It deviates from the "strict" FullyEncoded
694// mode in the following way:
695// - spaces are decoded
696// - valid UTF-8 sequences are decoded
697// - gen-delims that can be unambiguously transformed are decoded
698// - characters controlled by DecodeReserved are often decoded, though this behavior
699// can change depending on the subjective definition of "pretty"
700//
701// Note that the list of gen-delims that we can transform is different for the
702// user info (user name + password) and the authority (user info + host +
703// port).
704
705
706// list the recoding table modifications to be used with the recodeFromUser and
707// appendToUser functions, according to the rules above. Spaces and UTF-8
708// sequences are handled outside the tables.
709
710// the encodedXXX tables are run with the delimiters set to "leave" by default;
711// the decodedXXX tables are run with the delimiters set to "decode" by default
712// (except for the query, which doesn't use these functions)
713
714namespace {
715template <typename T> constexpr ushort decode(T x) noexcept { return ushort(x); }
716template <typename T> constexpr ushort leave(T x) noexcept { return ushort(0x100 | x); }
717template <typename T> constexpr ushort encode(T x) noexcept { return ushort(0x200 | x); }
718}
719
720static const ushort userNameInIsolation[] = {
721 decode(':'), // 0
722 decode('@'), // 1
723 decode(']'), // 2
724 decode('['), // 3
725 decode('/'), // 4
726 decode('?'), // 5
727 decode('#'), // 6
728
729 decode('"'), // 7
730 decode('<'),
731 decode('>'),
732 decode('^'),
733 decode('\\'),
734 decode('|'),
735 decode('{'),
736 decode('}'),
737 0
738};
740static const ushort * const pathInIsolation = userNameInIsolation + 5;
741static const ushort * const queryInIsolation = userNameInIsolation + 6;
743
744static const ushort userNameInUserInfo[] = {
745 encode(':'), // 0
746 decode('@'), // 1
747 decode(']'), // 2
748 decode('['), // 3
749 decode('/'), // 4
750 decode('?'), // 5
751 decode('#'), // 6
752
753 decode('"'), // 7
754 decode('<'),
755 decode('>'),
756 decode('^'),
757 decode('\\'),
758 decode('|'),
759 decode('{'),
760 decode('}'),
761 0
762};
764
765static const ushort userNameInAuthority[] = {
766 encode(':'), // 0
767 encode('@'), // 1
768 encode(']'), // 2
769 encode('['), // 3
770 decode('/'), // 4
771 decode('?'), // 5
772 decode('#'), // 6
773
774 decode('"'), // 7
775 decode('<'),
776 decode('>'),
777 decode('^'),
778 decode('\\'),
779 decode('|'),
780 decode('{'),
781 decode('}'),
782 0
783};
785
786static const ushort userNameInUrl[] = {
787 encode(':'), // 0
788 encode('@'), // 1
789 encode(']'), // 2
790 encode('['), // 3
791 encode('/'), // 4
792 encode('?'), // 5
793 encode('#'), // 6
794
795 // no need to list encode(x) for the other characters
796 0
797};
798static const ushort * const passwordInUrl = userNameInUrl + 1;
799static const ushort * const pathInUrl = userNameInUrl + 5;
800static const ushort * const queryInUrl = userNameInUrl + 6;
801static const ushort * const fragmentInUrl = userNameInUrl + 6;
802
804{
805 data.replace(u'%', "%25"_L1);
806}
807
808static inline QString
809recodeFromUser(const QString &input, const ushort *actions, qsizetype from, qsizetype to)
810{
812 const QChar *begin = input.constData() + from;
813 const QChar *end = input.constData() + to;
814 if (qt_urlRecode(output, QStringView{begin, end}, {}, actions))
815 return output;
816
817 return input.mid(from, to - from);
818}
819
820// appendXXXX functions: copy from the internal form to the external, user form.
821// the internal value is stored in its PrettyDecoded form, so that case is easy.
822static inline void appendToUser(QString &appendTo, QStringView value, QUrl::FormattingOptions options,
823 const ushort *actions)
824{
825 // The stored value is already QUrl::PrettyDecoded, so there's nothing to
826 // do if that's what the user asked for (test only
827 // ComponentFormattingOptions, ignore FormattingOptions).
828 if ((options & 0xFFFF0000) == QUrl::PrettyDecoded ||
829 !qt_urlRecode(appendTo, value, options, actions))
830 appendTo += value;
831
832 // copy nullness, if necessary, because QString::operator+=(QStringView) doesn't
833 if (appendTo.isNull() && !value.isNull())
834 appendTo.detach();
835}
836
837inline void QUrlPrivate::appendAuthority(QString &appendTo, QUrl::FormattingOptions options, Section appendingTo) const
838{
839 if ((options & QUrl::RemoveUserInfo) != QUrl::RemoveUserInfo) {
840 appendUserInfo(appendTo, options, appendingTo);
841
842 // add '@' only if we added anything
843 if (hasUserName() || (hasPassword() && (options & QUrl::RemovePassword) == 0))
844 appendTo += u'@';
845 }
846 appendHost(appendTo, options);
847 if (!(options & QUrl::RemovePort) && port != -1)
848 appendTo += u':' + QString::number(port);
849}
850
851inline void QUrlPrivate::appendUserInfo(QString &appendTo, QUrl::FormattingOptions options, Section appendingTo) const
852{
853 if (Q_LIKELY(!hasUserInfo()))
854 return;
855
856 const ushort *userNameActions;
857 const ushort *passwordActions;
858 if (options & QUrl::EncodeDelimiters) {
859 userNameActions = userNameInUrl;
860 passwordActions = passwordInUrl;
861 } else {
862 switch (appendingTo) {
863 case UserInfo:
864 userNameActions = userNameInUserInfo;
865 passwordActions = passwordInUserInfo;
866 break;
867
868 case Authority:
869 userNameActions = userNameInAuthority;
870 passwordActions = passwordInAuthority;
871 break;
872
873 case FullUrl:
874 userNameActions = userNameInUrl;
875 passwordActions = passwordInUrl;
876 break;
877
878 default:
879 // can't happen
880 Q_UNREACHABLE();
881 break;
882 }
883 }
884
885 if (!qt_urlRecode(appendTo, userName, options, userNameActions))
886 appendTo += userName;
887 if (options & QUrl::RemovePassword || !hasPassword()) {
888 return;
889 } else {
890 appendTo += u':';
891 if (!qt_urlRecode(appendTo, password, options, passwordActions))
892 appendTo += password;
893 }
894}
895
897{
898 // only called from QUrl::userName()
899 appendToUser(appendTo, userName, options,
901}
902
904{
905 // only called from QUrl::password()
906 appendToUser(appendTo, password, options,
908}
909
910inline void QUrlPrivate::appendPath(QString &appendTo, QUrl::FormattingOptions options, Section appendingTo) const
911{
912 QString thePath = path;
913 if (options & QUrl::NormalizePathSegments) {
915 }
916
917 QStringView thePathView(thePath);
918 if (options & QUrl::RemoveFilename) {
919 const qsizetype slash = path.lastIndexOf(u'/');
920 if (slash == -1)
921 return;
922 thePathView = QStringView{path}.left(slash + 1);
923 }
924 // check if we need to remove trailing slashes
925 if (options & QUrl::StripTrailingSlash) {
926 while (thePathView.size() > 1 && thePathView.endsWith(u'/'))
927 thePathView.chop(1);
928 }
929
930 appendToUser(appendTo, thePathView, options,
931 appendingTo == FullUrl || options & QUrl::EncodeDelimiters ? pathInUrl : pathInIsolation);
932}
933
934inline void QUrlPrivate::appendFragment(QString &appendTo, QUrl::FormattingOptions options, Section appendingTo) const
935{
936 appendToUser(appendTo, fragment, options,
938 appendingTo == FullUrl ? nullptr : fragmentInIsolation);
939}
940
941inline void QUrlPrivate::appendQuery(QString &appendTo, QUrl::FormattingOptions options, Section appendingTo) const
942{
943 appendToUser(appendTo, query, options,
944 appendingTo == FullUrl || options & QUrl::EncodeDelimiters ? queryInUrl : queryInIsolation);
945}
946
947// setXXX functions
948
949inline bool QUrlPrivate::setScheme(const QString &value, qsizetype len, bool doSetError)
950{
951 // schemes are strictly RFC-compliant:
952 // scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
953 // we also lowercase the scheme
954
955 // schemes in URLs are not allowed to be empty, but they can be in
956 // "Relative URIs" which QUrl also supports. QUrl::setScheme does
957 // not call us with len == 0, so this can only be from parse()
958 scheme.clear();
959 if (len == 0)
960 return false;
961
963
964 // validate it:
965 qsizetype needsLowercasing = -1;
966 const ushort *p = reinterpret_cast<const ushort *>(value.data());
967 for (qsizetype i = 0; i < len; ++i) {
968 if (isAsciiLower(p[i]))
969 continue;
970 if (isAsciiUpper(p[i])) {
971 needsLowercasing = i;
972 continue;
973 }
974 if (i) {
975 if (isAsciiDigit(p[i]))
976 continue;
977 if (p[i] == '+' || p[i] == '-' || p[i] == '.')
978 continue;
979 }
980
981 // found something else
982 // don't call setError needlessly:
983 // if we've been called from parse(), it will try to recover
984 if (doSetError)
986 return false;
987 }
988
989 scheme = value.left(len);
990
991 if (needsLowercasing != -1) {
992 // schemes are ASCII only, so we don't need the full Unicode toLower
993 QChar *schemeData = scheme.data(); // force detaching here
994 for (qsizetype i = needsLowercasing; i >= 0; --i) {
995 ushort c = schemeData[i].unicode();
996 if (isAsciiUpper(c))
997 schemeData[i] = QChar(c + 0x20);
998 }
999 }
1000
1001 // did we set to the file protocol?
1002 if (scheme == fileScheme()
1003#ifdef Q_OS_WIN
1004 || scheme == webDavScheme()
1005#endif
1006 ) {
1007 flags |= IsLocalFile;
1008 } else {
1009 flags &= ~IsLocalFile;
1010 }
1011 return true;
1012}
1013
1015{
1016 sectionIsPresent &= ~Authority;
1017 port = -1;
1018 if (from == end && !auth.isNull())
1019 sectionIsPresent |= Host; // empty but not null authority implies host
1020
1021 // we never actually _loop_
1022 while (from != end) {
1023 qsizetype userInfoIndex = auth.indexOf(u'@', from);
1024 if (size_t(userInfoIndex) < size_t(end)) {
1025 setUserInfo(auth, from, userInfoIndex);
1026 if (mode == QUrl::StrictMode && !validateComponent(UserInfo, auth, from, userInfoIndex))
1027 break;
1028 from = userInfoIndex + 1;
1029 }
1030
1031 qsizetype colonIndex = auth.lastIndexOf(u':', end - 1);
1032 if (colonIndex < from)
1033 colonIndex = -1;
1034
1035 if (size_t(colonIndex) < size_t(end)) {
1036 if (auth.at(from).unicode() == '[') {
1037 // check if colonIndex isn't inside the "[...]" part
1038 qsizetype closingBracket = auth.indexOf(u']', from);
1039 if (size_t(closingBracket) > size_t(colonIndex))
1040 colonIndex = -1;
1041 }
1042 }
1043
1044 if (size_t(colonIndex) < size_t(end) - 1) {
1045 // found a colon with digits after it
1046 unsigned long x = 0;
1047 for (qsizetype i = colonIndex + 1; i < end; ++i) {
1048 ushort c = auth.at(i).unicode();
1049 if (isAsciiDigit(c)) {
1050 x *= 10;
1051 x += c - '0';
1052 } else {
1053 x = ulong(-1); // x != ushort(x)
1054 break;
1055 }
1056 }
1057 if (x == ushort(x)) {
1058 port = ushort(x);
1059 } else {
1060 setError(InvalidPortError, auth, colonIndex + 1);
1061 if (mode == QUrl::StrictMode)
1062 break;
1063 }
1064 }
1065
1066 setHost(auth, from, qMin<size_t>(end, colonIndex), mode);
1067 if (mode == QUrl::StrictMode && !validateComponent(Host, auth, from, qMin<size_t>(end, colonIndex))) {
1068 // clear host too
1069 sectionIsPresent &= ~Authority;
1070 break;
1071 }
1072
1073 // success
1074 return;
1075 }
1076 // clear all sections but host
1077 sectionIsPresent &= ~Authority | Host;
1078 userName.clear();
1079 password.clear();
1080 host.clear();
1081 port = -1;
1082}
1083
1084inline void QUrlPrivate::setUserInfo(const QString &userInfo, qsizetype from, qsizetype end)
1085{
1086 qsizetype delimIndex = userInfo.indexOf(u':', from);
1087 setUserName(userInfo, from, qMin<size_t>(delimIndex, end));
1088
1089 if (size_t(delimIndex) >= size_t(end)) {
1090 password.clear();
1091 sectionIsPresent &= ~Password;
1092 } else {
1093 setPassword(userInfo, delimIndex + 1, end);
1094 }
1095}
1096
1102
1108
1110{
1111 // sectionIsPresent |= Path; // not used, save some cycles
1113}
1114
1120
1122{
1125}
1126
1127// Host handling
1128// The RFC says the host is:
1129// host = IP-literal / IPv4address / reg-name
1130// IP-literal = "[" ( IPv6address / IPvFuture ) "]"
1131// IPvFuture = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" )
1132// [a strict definition of IPv6Address and IPv4Address]
1133// reg-name = *( unreserved / pct-encoded / sub-delims )
1134//
1135// We deviate from the standard in all but IPvFuture. For IPvFuture we accept
1136// and store only exactly what the RFC says we should. No percent-encoding is
1137// permitted in this field, so Unicode characters and space aren't either.
1138//
1139// For IPv4 addresses, we accept broken addresses like inet_aton does (that is,
1140// less than three dots). However, we correct the address to the proper form
1141// and store the corrected address. After correction, we comply to the RFC and
1142// it's exclusively composed of unreserved characters.
1143//
1144// For IPv6 addresses, we accept addresses including trailing (embedded) IPv4
1145// addresses, the so-called v4-compat and v4-mapped addresses. We also store
1146// those addresses like that in the hostname field, which violates the spec.
1147// IPv6 hosts are stored with the square brackets in the QString. It also
1148// requires no transformation in any way.
1149//
1150// As for registered names, it's the other way around: we accept only valid
1151// hostnames as specified by STD 3 and IDNA. That means everything we accept is
1152// valid in the RFC definition above, but there are many valid reg-names
1153// according to the RFC that we do not accept in the name of security. Since we
1154// do accept IDNA, reg-names are subject to ACE encoding and decoding, which is
1155// specified by the DecodeUnicode flag. The hostname is stored in its Unicode form.
1156
1157inline void QUrlPrivate::appendHost(QString &appendTo, QUrl::FormattingOptions options) const
1158{
1159 if (host.isEmpty()) {
1160 if ((sectionIsPresent & Host) && appendTo.isNull())
1161 appendTo.detach();
1162 return;
1163 }
1164 if (host.at(0).unicode() == '[') {
1165 // IPv6 addresses might contain a zone-id which needs to be recoded
1166 if (options != 0)
1167 if (qt_urlRecode(appendTo, host, options, nullptr))
1168 return;
1169 appendTo += host;
1170 } else {
1171 // this is either an IPv4Address or a reg-name
1172 // if it is a reg-name, it is already stored in Unicode form
1173 if (options & QUrl::EncodeUnicode && !(options & 0x4000000))
1174 appendTo += qt_ACE_do(host, ToAceOnly, AllowLeadingDot, {});
1175 else
1176 appendTo += host;
1177 }
1178}
1179
1180// the whole IPvFuture is passed and parsed here, including brackets;
1181// returns null if the parsing was successful, or the QChar of the first failure
1182static const QChar *parseIpFuture(QString &host, const QChar *begin, const QChar *end, QUrl::ParsingMode mode)
1183{
1184 // IPvFuture = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" )
1185 static const char acceptable[] =
1186 "!$&'()*+,;=" // sub-delims
1187 ":" // ":"
1188 "-._~"; // unreserved
1189
1190 // the brackets and the "v" have been checked
1191 const QChar *const origBegin = begin;
1192 if (begin[3].unicode() != '.')
1193 return &begin[3];
1194 if (isHexDigit(begin[2].unicode())) {
1195 // this is so unlikely that we'll just go down the slow path
1196 // decode the whole string, skipping the "[vH." and "]" which we already know to be there
1197 host += QStringView(begin, 4);
1198
1199 // uppercase the version, if necessary
1200 if (begin[2].unicode() >= 'a')
1201 host[host.size() - 2] = QChar{begin[2].unicode() - 0x20};
1202
1203 begin += 4;
1204 --end;
1205
1206 QString decoded;
1208 begin = decoded.constBegin();
1209 end = decoded.constEnd();
1210 }
1211
1212 for ( ; begin != end; ++begin) {
1213 if (isAsciiLetterOrNumber(begin->unicode()))
1214 host += *begin;
1215 else if (begin->unicode() < 0x80 && strchr(acceptable, begin->unicode()) != nullptr)
1216 host += *begin;
1217 else
1218 return decoded.isEmpty() ? begin : &origBegin[2];
1219 }
1220 host += u']';
1221 return nullptr;
1222 }
1223 return &origBegin[2];
1224}
1225
1226// ONLY the IPv6 address is parsed here, WITHOUT the brackets
1227static const QChar *parseIp6(QString &host, const QChar *begin, const QChar *end, QUrl::ParsingMode mode)
1228{
1229 QStringView decoded(begin, end);
1230 QString decodedBuffer;
1231 if (mode == QUrl::TolerantMode) {
1232 // this struct is kept in automatic storage because it's only 4 bytes
1233 const ushort decodeColon[] = { decode(':'), 0 };
1234 if (qt_urlRecode(decodedBuffer, decoded, QUrl::ComponentFormattingOption::PrettyDecoded, decodeColon))
1235 decoded = decodedBuffer;
1236 }
1237
1238 const QStringView zoneIdIdentifier(u"%25");
1240 QStringView zoneId;
1241
1242 qsizetype zoneIdPosition = decoded.indexOf(zoneIdIdentifier);
1243 if ((zoneIdPosition != -1) && (decoded.lastIndexOf(zoneIdIdentifier) == zoneIdPosition)) {
1244 zoneId = decoded.mid(zoneIdPosition + zoneIdIdentifier.size());
1245 decoded.truncate(zoneIdPosition);
1246
1247 // was there anything after the zone ID separator?
1248 if (zoneId.isEmpty())
1249 return end;
1250 }
1251
1252 // did the address become empty after removing the zone ID?
1253 // (it might have always been empty)
1254 if (decoded.isEmpty())
1255 return end;
1256
1257 const QChar *ret = QIPAddressUtils::parseIp6(address, decoded.constBegin(), decoded.constEnd());
1258 if (ret)
1259 return begin + (ret - decoded.constBegin());
1260
1261 host.reserve(host.size() + (end - begin) + 2); // +2 for the brackets
1262 host += u'[';
1264
1265 if (!zoneId.isEmpty()) {
1266 host += zoneIdIdentifier;
1267 host += zoneId;
1268 }
1269 host += u']';
1270 return nullptr;
1271}
1272
1273inline bool
1275{
1276 const QChar *begin = value.constData() + from;
1277 const QChar *end = value.constData() + iend;
1278
1279 const qsizetype len = end - begin;
1280 host.clear();
1281 sectionIsPresent &= ~Host;
1282 if (!value.isNull() || (sectionIsPresent & Authority))
1284 if (len == 0)
1285 return true;
1286
1287 if (begin[0].unicode() == '[') {
1288 // IPv6Address or IPvFuture
1289 // smallest IPv6 address is "[::]" (len = 4)
1290 // smallest IPvFuture address is "[v7.X]" (len = 6)
1291 if (end[-1].unicode() != ']') {
1293 return false;
1294 }
1295
1296 if (len > 5 && begin[1].unicode() == 'v') {
1297 const QChar *c = parseIpFuture(host, begin, end, mode);
1298 if (c)
1299 setError(InvalidIPvFutureError, value, c - value.constData());
1300 return !c;
1301 } else if (begin[1].unicode() == 'v') {
1303 }
1304
1305 const QChar *c = parseIp6(host, begin + 1, end - 1, mode);
1306 if (!c)
1307 return true;
1308
1309 if (c == end - 1)
1311 else
1313 return false;
1314 }
1315
1316 // check if it's an IPv4 address
1318 if (QIPAddressUtils::parseIp4(ip4, begin, end)) {
1319 // yes, it was
1321 return true;
1322 }
1323
1324 // This is probably a reg-name.
1325 // But it can also be an encoded string that, when decoded becomes one
1326 // of the types above.
1327 //
1328 // Two types of encoding are possible:
1329 // percent encoding (e.g., "%31%30%2E%30%2E%30%2E%31" -> "10.0.0.1")
1330 // Unicode encoding (some non-ASCII characters case-fold to digits
1331 // when nameprepping is done)
1332 //
1333 // The qt_ACE_do function below does IDNA normalization and the STD3 check.
1334 // That means a Unicode string may become an IPv4 address, but it cannot
1335 // produce a '[' or a '%'.
1336
1337 // check for percent-encoding first
1338 QString s;
1339 if (mode == QUrl::TolerantMode && qt_urlRecode(s, QStringView{begin, end}, { }, nullptr)) {
1340 // something was decoded
1341 // anything encoded left?
1342 qsizetype pos = s.indexOf(QChar(0x25)); // '%'
1343 if (pos != -1) {
1345 return false;
1346 }
1347
1348 // recurse
1349 return setHost(s, 0, s.size(), QUrl::StrictMode);
1350 }
1351
1352 s = qt_ACE_do(value.mid(from, iend - from), NormalizeAce, ForbidLeadingDot, {});
1353 if (s.isEmpty()) {
1355 return false;
1356 }
1357
1358 // check IPv4 again
1359 if (QIPAddressUtils::parseIp4(ip4, s.constBegin(), s.constEnd())) {
1361 } else {
1362 host = s;
1363 }
1364 return true;
1365}
1366
1367inline void QUrlPrivate::parse(const QString &url, QUrl::ParsingMode parsingMode)
1368{
1369 // URI-reference = URI / relative-ref
1370 // URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
1371 // relative-ref = relative-part [ "?" query ] [ "#" fragment ]
1372 // hier-part = "//" authority path-abempty
1373 // / other path types
1374 // relative-part = "//" authority path-abempty
1375 // / other path types here
1376
1377 sectionIsPresent = 0;
1378 flags = 0;
1379 clearError();
1380
1381 // find the important delimiters
1382 qsizetype colon = -1;
1383 qsizetype question = -1;
1384 qsizetype hash = -1;
1385 const qsizetype len = url.size();
1386 const QChar *const begin = url.constData();
1387 const ushort *const data = reinterpret_cast<const ushort *>(begin);
1388
1389 for (qsizetype i = 0; i < len; ++i) {
1390 size_t uc = data[i];
1391 if (uc == '#' && hash == -1) {
1392 hash = i;
1393
1394 // nothing more to be found
1395 break;
1396 }
1397
1398 if (question == -1) {
1399 if (uc == ':' && colon == -1)
1400 colon = i;
1401 else if (uc == '?')
1402 question = i;
1403 }
1404 }
1405
1406 // check if we have a scheme
1407 qsizetype hierStart;
1408 if (colon != -1 && setScheme(url, colon, /* don't set error */ false)) {
1409 hierStart = colon + 1;
1410 } else {
1411 // recover from a failed scheme: it might not have been a scheme at all
1412 scheme.clear();
1413 sectionIsPresent = 0;
1414 hierStart = 0;
1415 }
1416
1417 qsizetype pathStart;
1418 qsizetype hierEnd = qMin<size_t>(qMin<size_t>(question, hash), len);
1419 if (hierEnd - hierStart >= 2 && data[hierStart] == '/' && data[hierStart + 1] == '/') {
1420 // we have an authority, it ends at the first slash after these
1421 qsizetype authorityEnd = hierEnd;
1422 for (qsizetype i = hierStart + 2; i < authorityEnd ; ++i) {
1423 if (data[i] == '/') {
1424 authorityEnd = i;
1425 break;
1426 }
1427 }
1428
1429 setAuthority(url, hierStart + 2, authorityEnd, parsingMode);
1430
1431 // even if we failed to set the authority properly, let's try to recover
1432 pathStart = authorityEnd;
1433 setPath(url, pathStart, hierEnd);
1434 } else {
1435 userName.clear();
1436 password.clear();
1437 host.clear();
1438 port = -1;
1439 pathStart = hierStart;
1440
1441 if (hierStart < hierEnd)
1442 setPath(url, hierStart, hierEnd);
1443 else
1444 path.clear();
1445 }
1446
1447 if (size_t(question) < size_t(hash))
1448 setQuery(url, question + 1, qMin<size_t>(hash, len));
1449
1450 if (hash != -1)
1451 setFragment(url, hash + 1, len);
1452
1453 if (error || parsingMode == QUrl::TolerantMode)
1454 return;
1455
1456 // The parsing so far was partially tolerant of errors, except for the
1457 // scheme parser (which is always strict) and the authority (which was
1458 // executed in strict mode).
1459 // If we haven't found any errors so far, continue the strict-mode parsing
1460 // from the path component onwards.
1461
1462 if (!validateComponent(Path, url, pathStart, hierEnd))
1463 return;
1464 if (size_t(question) < size_t(hash) && !validateComponent(Query, url, question + 1, qMin<size_t>(hash, len)))
1465 return;
1466 if (hash != -1)
1468}
1469
1471{
1472 QString tmp;
1473 QString ourPath;
1474 appendPath(ourPath, options, QUrlPrivate::Path);
1475
1476 // magic for shared drive on windows
1477 if (!host.isEmpty()) {
1478 tmp = "//"_L1 + host;
1479#ifdef Q_OS_WIN // QTBUG-42346, WebDAV is visible as local file on Windows only.
1480 if (scheme == webDavScheme())
1481 tmp += webDavSslTag();
1482#endif
1483 if (!ourPath.isEmpty() && !ourPath.startsWith(u'/'))
1484 tmp += u'/';
1485 tmp += ourPath;
1486 } else {
1487 tmp = ourPath;
1488#ifdef Q_OS_WIN
1489 // magic for drives on windows
1490 if (ourPath.length() > 2 && ourPath.at(0) == u'/' && ourPath.at(2) == u':')
1491 tmp.remove(0, 1);
1492#endif
1493 }
1494 return tmp;
1495}
1496
1497/*
1498 From http://www.ietf.org/rfc/rfc3986.txt, 5.2.3: Merge paths
1499
1500 Returns a merge of the current path with the relative path passed
1501 as argument.
1502
1503 Note: \a relativePath is relative (does not start with '/').
1504*/
1505inline QString QUrlPrivate::mergePaths(const QString &relativePath) const
1506{
1507 // If the base URI has a defined authority component and an empty
1508 // path, then return a string consisting of "/" concatenated with
1509 // the reference's path; otherwise,
1510 if (!host.isEmpty() && path.isEmpty())
1511 return u'/' + relativePath;
1512
1513 // Return a string consisting of the reference's path component
1514 // appended to all but the last segment of the base URI's path
1515 // (i.e., excluding any characters after the right-most "/" in the
1516 // base URI path, or excluding the entire base URI path if it does
1517 // not contain any "/" characters).
1518 QString newPath;
1519 if (!path.contains(u'/'))
1520 newPath = relativePath;
1521 else
1522 newPath = QStringView{path}.left(path.lastIndexOf(u'/') + 1) + relativePath;
1523
1524 return newPath;
1525}
1526
1527/*
1528 From http://www.ietf.org/rfc/rfc3986.txt, 5.2.4: Remove dot segments
1529
1530 Removes unnecessary ../ and ./ from the path. Used for normalizing
1531 the URL.
1532*/
1534{
1535 // The input buffer is initialized with the now-appended path
1536 // components and the output buffer is initialized to the empty
1537 // string.
1538 QChar *out = path->data();
1539 const QChar *in = out;
1540 const QChar *end = out + path->size();
1541
1542 // If the input buffer consists only of
1543 // "." or "..", then remove that from the input
1544 // buffer;
1545 if (path->size() == 1 && in[0].unicode() == '.')
1546 ++in;
1547 else if (path->size() == 2 && in[0].unicode() == '.' && in[1].unicode() == '.')
1548 in += 2;
1549 // While the input buffer is not empty, loop:
1550 while (in < end) {
1551
1552 // otherwise, if the input buffer begins with a prefix of "../" or "./",
1553 // then remove that prefix from the input buffer;
1554 if (path->size() >= 2 && in[0].unicode() == '.' && in[1].unicode() == '/')
1555 in += 2;
1556 else if (path->size() >= 3 && in[0].unicode() == '.'
1557 && in[1].unicode() == '.' && in[2].unicode() == '/')
1558 in += 3;
1559
1560 // otherwise, if the input buffer begins with a prefix of
1561 // "/./" or "/.", where "." is a complete path segment,
1562 // then replace that prefix with "/" in the input buffer;
1563 if (in <= end - 3 && in[0].unicode() == '/' && in[1].unicode() == '.'
1564 && in[2].unicode() == '/') {
1565 in += 2;
1566 continue;
1567 } else if (in == end - 2 && in[0].unicode() == '/' && in[1].unicode() == '.') {
1568 *out++ = u'/';
1569 in += 2;
1570 break;
1571 }
1572
1573 // otherwise, if the input buffer begins with a prefix
1574 // of "/../" or "/..", where ".." is a complete path
1575 // segment, then replace that prefix with "/" in the
1576 // input buffer and remove the last //segment and its
1577 // preceding "/" (if any) from the output buffer;
1578 if (in <= end - 4 && in[0].unicode() == '/' && in[1].unicode() == '.'
1579 && in[2].unicode() == '.' && in[3].unicode() == '/') {
1580 while (out > path->constData() && (--out)->unicode() != '/')
1581 ;
1582 if (out == path->constData() && out->unicode() != '/')
1583 ++in;
1584 in += 3;
1585 continue;
1586 } else if (in == end - 3 && in[0].unicode() == '/' && in[1].unicode() == '.'
1587 && in[2].unicode() == '.') {
1588 while (out > path->constData() && (--out)->unicode() != '/')
1589 ;
1590 if (out->unicode() == '/')
1591 ++out;
1592 in += 3;
1593 break;
1594 }
1595
1596 // otherwise move the first path segment in
1597 // the input buffer to the end of the output
1598 // buffer, including the initial "/" character
1599 // (if any) and any subsequent characters up
1600 // to, but not including, the next "/"
1601 // character or the end of the input buffer.
1602 *out++ = *in++;
1603 while (in < end && in->unicode() != '/')
1604 *out++ = *in++;
1605 }
1606 path->truncate(out - path->constData());
1607}
1608
1610{
1611 Q_ASSERT(!source == !position);
1612 if (error) {
1613 if (source) {
1614 *source = error->source;
1615 *position = error->position;
1616 }
1617 return error->code;
1618 }
1619
1620 // There are three more cases of invalid URLs that QUrl recognizes and they
1621 // are only possible with constructed URLs (setXXX methods), not with
1622 // parsing. Therefore, they are tested here.
1623 //
1624 // Two cases are a non-empty path that doesn't start with a slash and:
1625 // - with an authority
1626 // - without an authority, without scheme but the path with a colon before
1627 // the first slash
1628 // The third case is an empty authority and a non-empty path that starts
1629 // with "//".
1630 // Those cases are considered invalid because toString() would produce a URL
1631 // that wouldn't be parsed back to the same QUrl.
1632
1633 if (path.isEmpty())
1634 return NoError;
1635 if (path.at(0) == u'/') {
1636 if (hasAuthority() || path.size() == 1 || path.at(1) != u'/')
1637 return NoError;
1638 if (source) {
1639 *source = path;
1640 *position = 0;
1641 }
1643 }
1644
1646 if (source) {
1647 *source = path;
1648 *position = 0;
1649 }
1651 }
1653 return NoError;
1654
1655 // check for a path of "text:text/"
1656 for (qsizetype i = 0; i < path.size(); ++i) {
1657 ushort c = path.at(i).unicode();
1658 if (c == '/') {
1659 // found the slash before the colon
1660 return NoError;
1661 }
1662 if (c == ':') {
1663 // found the colon before the slash, it's invalid
1664 if (source) {
1665 *source = path;
1666 *position = i;
1667 }
1669 }
1670 }
1671 return NoError;
1672}
1673
1676{
1677 // What we need to look out for, that the regular parser tolerates:
1678 // - percent signs not followed by two hex digits
1679 // - forbidden characters, which should always appear encoded
1680 // '"' / '<' / '>' / '\' / '^' / '`' / '{' / '|' / '}' / BKSP
1681 // control characters
1682 // - delimiters not allowed in certain positions
1683 // . scheme: parser is already strict
1684 // . user info: gen-delims except ":" disallowed ("/" / "?" / "#" / "[" / "]" / "@")
1685 // . host: parser is stricter than the standard
1686 // . port: parser is stricter than the standard
1687 // . path: all delimiters allowed
1688 // . fragment: all delimiters allowed
1689 // . query: all delimiters allowed
1690 static const char forbidden[] = "\"<>\\^`{|}\x7F";
1691 static const char forbiddenUserInfo[] = ":/?#[]@";
1692
1693 Q_ASSERT(section != Authority && section != Hierarchy && section != FullUrl);
1694
1695 const ushort *const data = reinterpret_cast<const ushort *>(input.constData());
1696 for (size_t i = size_t(begin); i < size_t(end); ++i) {
1697 uint uc = data[i];
1698 if (uc >= 0x80)
1699 continue;
1700
1701 bool error = false;
1702 if ((uc == '%' && (size_t(end) < i + 2 || !isHex(data[i + 1]) || !isHex(data[i + 2])))
1703 || uc <= 0x20 || strchr(forbidden, uc)) {
1704 // found an error
1705 error = true;
1706 } else if (section & UserInfo) {
1707 if (section == UserInfo && strchr(forbiddenUserInfo + 1, uc))
1708 error = true;
1709 else if (section != UserInfo && strchr(forbiddenUserInfo, uc))
1710 error = true;
1711 }
1712
1713 if (!error)
1714 continue;
1715
1716 ErrorCode errorCode = ErrorCode(int(section) << 8);
1717 if (section == UserInfo) {
1718 // is it the user name or the password?
1719 errorCode = InvalidUserNameError;
1720 for (size_t j = size_t(begin); j < i; ++j)
1721 if (data[j] == ':') {
1722 errorCode = InvalidPasswordError;
1723 break;
1724 }
1725 }
1726
1727 setError(errorCode, input, i);
1728 return false;
1729 }
1730
1731 // no errors
1732 return true;
1733}
1734
1735#if 0
1736inline void QUrlPrivate::validate() const
1737{
1738 QUrlPrivate *that = (QUrlPrivate *)this;
1739 that->encodedOriginal = that->toEncoded(); // may detach
1740 parse(ParseOnly);
1741
1742 QURL_SETFLAG(that->stateFlags, Validated);
1743
1744 if (!isValid)
1745 return;
1746
1747 QString auth = authority(); // causes the non-encoded forms to be valid
1748
1749 // authority() calls canonicalHost() which sets this
1750 if (!isHostValid)
1751 return;
1752
1753 if (scheme == "mailto"_L1) {
1754 if (!host.isEmpty() || port != -1 || !userName.isEmpty() || !password.isEmpty()) {
1755 that->isValid = false;
1756 that->errorInfo.setParams(0, QT_TRANSLATE_NOOP(QUrl, "expected empty host, username,"
1757 "port and password"),
1758 0, 0);
1759 }
1760 } else if (scheme == ftpScheme() || scheme == httpScheme()) {
1761 if (host.isEmpty() && !(path.isEmpty() && encodedPath.isEmpty())) {
1762 that->isValid = false;
1763 that->errorInfo.setParams(0, QT_TRANSLATE_NOOP(QUrl, "the host is empty, but not the path"),
1764 0, 0);
1765 }
1766 }
1767}
1768#endif
1769
1844{
1845 setUrl(url, parsingMode);
1846}
1847
1852{
1853}
1854
1858QUrl::QUrl(const QUrl &other) noexcept : d(other.d)
1859{
1860 if (d)
1861 d->ref.ref();
1862}
1863
1868{
1869 if (d && !d->ref.deref())
1870 delete d;
1871}
1872
1882bool QUrl::isValid() const
1883{
1884 if (isEmpty()) {
1885 // also catches d == nullptr
1886 return false;
1887 }
1888 return d->validityError() == QUrlPrivate::NoError;
1889}
1890
1896bool QUrl::isEmpty() const
1897{
1898 if (!d) return true;
1899 return d->isEmpty();
1900}
1901
1910{
1911 if (d && !d->ref.deref())
1912 delete d;
1913 d = nullptr;
1914}
1915
1934void QUrl::setUrl(const QString &url, ParsingMode parsingMode)
1935{
1936 if (parsingMode == DecodedMode) {
1937 qWarning("QUrl: QUrl::DecodedMode is not permitted when parsing a full URL");
1938 } else {
1939 detach();
1940 d->parse(url, parsingMode);
1941 }
1942}
1943
1967void QUrl::setScheme(const QString &scheme)
1968{
1969 detach();
1970 d->clearError();
1971 if (scheme.isEmpty()) {
1972 // schemes are not allowed to be empty
1973 d->sectionIsPresent &= ~QUrlPrivate::Scheme;
1974 d->flags &= ~QUrlPrivate::IsLocalFile;
1975 d->scheme.clear();
1976 } else {
1977 d->setScheme(scheme, scheme.size(), /* do set error */ true);
1978 }
1979}
1980
1992{
1993 if (!d) return QString();
1994
1995 return d->scheme;
1996}
1997
2028{
2029 detach();
2030 d->clearError();
2031
2032 if (mode == DecodedMode) {
2033 qWarning("QUrl::setAuthority(): QUrl::DecodedMode is not permitted in this function");
2034 return;
2035 }
2036
2038}
2039
2055QString QUrl::authority(ComponentFormattingOptions options) const
2056{
2058 if (!d)
2059 return result;
2060
2061 if (options == QUrl::FullyDecoded) {
2062 qWarning("QUrl::authority(): QUrl::FullyDecoded is not permitted in this function");
2063 return result;
2064 }
2065
2067 return result;
2068}
2069
2094{
2095 detach();
2096 d->clearError();
2097 QString trimmed = userInfo.trimmed();
2098 if (mode == DecodedMode) {
2099 qWarning("QUrl::setUserInfo(): QUrl::DecodedMode is not permitted in this function");
2100 return;
2101 }
2102
2103 d->setUserInfo(trimmed, 0, trimmed.size());
2104 if (userInfo.isNull()) {
2105 // QUrlPrivate::setUserInfo cleared almost everything
2106 // but it leaves the UserName bit set
2107 d->sectionIsPresent &= ~QUrlPrivate::UserInfo;
2109 d->sectionIsPresent &= ~QUrlPrivate::UserInfo;
2110 d->userName.clear();
2111 d->password.clear();
2112 }
2113}
2114
2129QString QUrl::userInfo(ComponentFormattingOptions options) const
2130{
2132 if (!d)
2133 return result;
2134
2135 if (options == QUrl::FullyDecoded) {
2136 qWarning("QUrl::userInfo(): QUrl::FullyDecoded is not permitted in this function");
2137 return result;
2138 }
2139
2141 return result;
2142}
2143
2165{
2166 detach();
2167 d->clearError();
2168
2170 if (mode == DecodedMode) {
2173 }
2174
2175 d->setUserName(data, 0, data.size());
2176 if (userName.isNull())
2177 d->sectionIsPresent &= ~QUrlPrivate::UserName;
2179 d->userName.clear();
2180}
2181
2199QString QUrl::userName(ComponentFormattingOptions options) const
2200{
2202 if (d)
2203 d->appendUserName(result, options);
2204 return result;
2205}
2206
2228{
2229 detach();
2230 d->clearError();
2231
2233 if (mode == DecodedMode) {
2236 }
2237
2238 d->setPassword(data, 0, data.size());
2239 if (password.isNull())
2240 d->sectionIsPresent &= ~QUrlPrivate::Password;
2242 d->password.clear();
2243}
2244
2262QString QUrl::password(ComponentFormattingOptions options) const
2263{
2265 if (d)
2266 d->appendPassword(result, options);
2267 return result;
2268}
2269
2290{
2291 detach();
2292 d->clearError();
2293
2294 QString data = host;
2295 if (mode == DecodedMode) {
2298 }
2299
2300 if (d->setHost(data, 0, data.size(), mode)) {
2301 return;
2302 } else if (!data.startsWith(u'[')) {
2303 // setHost failed, it might be IPv6 or IPvFuture in need of bracketing
2304 Q_ASSERT(d->error);
2305
2306 data.prepend(u'[');
2307 data.append(u']');
2308 if (!d->setHost(data, 0, data.size(), mode)) {
2309 // failed again
2310 if (data.contains(u':')) {
2311 // source data contains ':', so it's an IPv6 error
2313 }
2314 d->sectionIsPresent &= ~QUrlPrivate::Host;
2315 } else {
2316 // succeeded
2317 d->clearError();
2318 }
2319 }
2320}
2321
2340QString QUrl::host(ComponentFormattingOptions options) const
2341{
2343 if (d) {
2344 d->appendHost(result, options);
2345 if (result.startsWith(u'['))
2346 result = result.mid(1, result.size() - 2);
2347 }
2348 return result;
2349}
2350
2359{
2360 detach();
2361 d->clearError();
2362
2363 if (port < -1 || port > 65535) {
2365 port = -1;
2366 }
2367
2368 d->port = port;
2369 if (port != -1)
2371}
2372
2383int QUrl::port(int defaultPort) const
2384{
2385 if (!d) return defaultPort;
2386 return d->port == -1 ? defaultPort : d->port;
2387}
2388
2415{
2416 detach();
2417 d->clearError();
2418
2419 QString data = path;
2420 if (mode == DecodedMode) {
2423 }
2424
2425 d->setPath(data, 0, data.size());
2426
2427 // optimized out, since there is no path delimiter
2428// if (path.isNull())
2429// d->sectionIsPresent &= ~QUrlPrivate::Path;
2430// else
2432 d->path.clear();
2433}
2434
2468QString QUrl::path(ComponentFormattingOptions options) const
2469{
2471 if (d)
2472 d->appendPath(result, options, QUrlPrivate::Path);
2473 return result;
2474}
2475
2497QString QUrl::fileName(ComponentFormattingOptions options) const
2498{
2499 const QString ourPath = path(options);
2500 const qsizetype slash = ourPath.lastIndexOf(u'/');
2501 if (slash == -1)
2502 return ourPath;
2503 return ourPath.mid(slash + 1);
2504}
2505
2513bool QUrl::hasQuery() const
2514{
2515 if (!d) return false;
2516 return d->hasQuery();
2517}
2518
2551{
2552 detach();
2553 d->clearError();
2554
2555 QString data = query;
2556 if (mode == DecodedMode) {
2559 }
2560
2561 d->setQuery(data, 0, data.size());
2562 if (query.isNull())
2563 d->sectionIsPresent &= ~QUrlPrivate::Query;
2565 d->query.clear();
2566}
2567
2580{
2581 detach();
2582 d->clearError();
2583
2584 // we know the data is in the right format
2585 d->query = query.toString();
2586 if (query.isEmpty())
2587 d->sectionIsPresent &= ~QUrlPrivate::Query;
2588 else
2590}
2591
2609QString QUrl::query(ComponentFormattingOptions options) const
2610{
2612 if (d) {
2614 if (d->hasQuery() && result.isNull())
2615 result.detach();
2616 }
2617 return result;
2618}
2619
2649{
2650 detach();
2651 d->clearError();
2652
2654 if (mode == DecodedMode) {
2657 }
2658
2659 d->setFragment(data, 0, data.size());
2660 if (fragment.isNull())
2663 d->fragment.clear();
2664}
2665
2682QString QUrl::fragment(ComponentFormattingOptions options) const
2683{
2685 if (d) {
2687 if (d->hasFragment() && result.isNull())
2688 result.detach();
2689 }
2690 return result;
2691}
2692
2701{
2702 if (!d) return false;
2703 return d->hasFragment();
2704}
2705
2725QUrl QUrl::resolved(const QUrl &relative) const
2726{
2727 if (!d) return relative;
2728 if (!relative.d) return *this;
2729
2730 QUrl t;
2731 if (!relative.d->scheme.isEmpty()) {
2732 t = relative;
2733 t.detach();
2734 } else {
2735 if (relative.d->hasAuthority()) {
2736 t = relative;
2737 t.detach();
2738 } else {
2739 t.d = new QUrlPrivate;
2740
2741 // copy the authority
2742 t.d->userName = d->userName;
2743 t.d->password = d->password;
2744 t.d->host = d->host;
2745 t.d->port = d->port;
2746 t.d->sectionIsPresent = d->sectionIsPresent & QUrlPrivate::Authority;
2747
2748 if (relative.d->path.isEmpty()) {
2749 t.d->path = d->path;
2750 if (relative.d->hasQuery()) {
2751 t.d->query = relative.d->query;
2752 t.d->sectionIsPresent |= QUrlPrivate::Query;
2753 } else if (d->hasQuery()) {
2754 t.d->query = d->query;
2755 t.d->sectionIsPresent |= QUrlPrivate::Query;
2756 }
2757 } else {
2758 t.d->path = relative.d->path.startsWith(u'/')
2759 ? relative.d->path
2760 : d->mergePaths(relative.d->path);
2761 if (relative.d->hasQuery()) {
2762 t.d->query = relative.d->query;
2763 t.d->sectionIsPresent |= QUrlPrivate::Query;
2764 }
2765 }
2766 }
2767 t.d->scheme = d->scheme;
2768 if (d->hasScheme())
2769 t.d->sectionIsPresent |= QUrlPrivate::Scheme;
2770 else
2771 t.d->sectionIsPresent &= ~QUrlPrivate::Scheme;
2773 }
2774 t.d->fragment = relative.d->fragment;
2775 if (relative.d->hasFragment())
2776 t.d->sectionIsPresent |= QUrlPrivate::Fragment;
2777 else
2778 t.d->sectionIsPresent &= ~QUrlPrivate::Fragment;
2779
2780 removeDotsFromPath(&t.d->path);
2781
2782#if defined(QURL_DEBUG)
2783 qDebug("QUrl(\"%ls\").resolved(\"%ls\") = \"%ls\"",
2785 qUtf16Printable(relative.url()),
2786 qUtf16Printable(t.url()));
2787#endif
2788 return t;
2789}
2790
2801{
2802 if (!d) return true;
2803 return !d->hasScheme();
2804}
2805
2818{
2819 return toString(options);
2820}
2821
2832{
2833 QString url;
2834 if (!isValid()) {
2835 // also catches isEmpty()
2836 return url;
2837 }
2838 if ((options & QUrl::FullyDecoded) == QUrl::FullyDecoded) {
2839 qWarning("QUrl: QUrl::FullyDecoded is not permitted when reconstructing the full URL");
2840 options &= ~QUrl::FullyDecoded;
2841 //options |= QUrl::PrettyDecoded; // no-op, value is 0
2842 }
2843
2844 // return just the path if:
2845 // - QUrl::PreferLocalFile is passed
2846 // - QUrl::RemovePath isn't passed (rather stupid if the user did...)
2847 // - there's no query or fragment to return
2848 // that is, either they aren't present, or we're removing them
2849 // - it's a local file
2851 && (!d->hasQuery() || options.testFlag(QUrl::RemoveQuery))
2852 && (!d->hasFragment() || options.testFlag(QUrl::RemoveFragment))
2853 && isLocalFile()) {
2854 url = d->toLocalFile(options | QUrl::FullyDecoded);
2855 return url;
2856 }
2857
2858 // for the full URL, we consider that the reserved characters are prettier if encoded
2859 if (options & DecodeReserved)
2860 options &= ~EncodeReserved;
2861 else
2862 options |= EncodeReserved;
2863
2864 if (!(options & QUrl::RemoveScheme) && d->hasScheme())
2865 url += d->scheme + u':';
2866
2867 bool pathIsAbsolute = d->path.startsWith(u'/');
2868 if (!((options & QUrl::RemoveAuthority) == QUrl::RemoveAuthority) && d->hasAuthority()) {
2869 url += "//"_L1;
2871 } else if (isLocalFile() && pathIsAbsolute) {
2872 // Comply with the XDG file URI spec, which requires triple slashes.
2873 url += "//"_L1;
2874 }
2875
2876 if (!(options & QUrl::RemovePath))
2877 d->appendPath(url, options, QUrlPrivate::FullUrl);
2878
2879 if (!(options & QUrl::RemoveQuery) && d->hasQuery()) {
2880 url += u'?';
2881 d->appendQuery(url, options, QUrlPrivate::FullUrl);
2882 }
2883 if (!(options & QUrl::RemoveFragment) && d->hasFragment()) {
2884 url += u'#';
2886 }
2887
2888 return url;
2889}
2890
2907{
2908 return toString(options | RemovePassword);
2909}
2910
2925{
2926 if (!isValid()) {
2927 // also catches isEmpty()
2928 return QUrl();
2929 }
2930 QUrl that = *this;
2931 if (options & RemoveScheme)
2932 that.setScheme(QString());
2933 if ((options & RemoveAuthority) == RemoveAuthority) {
2934 that.setAuthority(QString());
2935 } else {
2936 if ((options & RemoveUserInfo) == RemoveUserInfo)
2937 that.setUserInfo(QString());
2938 else if (options & RemovePassword)
2939 that.setPassword(QString());
2940 if (options & RemovePort)
2941 that.setPort(-1);
2942 }
2943 if (options & RemoveQuery)
2944 that.setQuery(QString());
2945 if (options & RemoveFragment)
2946 that.setFragment(QString());
2947 if (options & RemovePath) {
2948 that.setPath(QString());
2949 } else if (options & (StripTrailingSlash | RemoveFilename | NormalizePathSegments)) {
2950 that.detach();
2951 QString path;
2953 that.d->setPath(path, 0, path.size());
2954 }
2955 return that;
2956}
2957
2968{
2969 options &= ~(FullyDecoded | FullyEncoded);
2970 return toString(options | FullyEncoded).toLatin1();
2971}
2972
2992
3006
3020{
3021 return input.toUtf8().toPercentEncoding(exclude, include);
3022}
3023
3041QString QUrl::fromAce(const QByteArray &domain, QUrl::AceProcessingOptions options)
3042{
3044 ForbidLeadingDot /*FIXME: make configurable*/, options);
3045}
3046
3064QByteArray QUrl::toAce(const QString &domain, AceProcessingOptions options)
3065{
3066 return qt_ACE_do(domain, ToAceOnly, ForbidLeadingDot /*FIXME: make configurable*/, options)
3067 .toLatin1();
3068}
3069
3080{
3081 if (!lhs.d || !rhs.d) {
3082 bool thisIsEmpty = !lhs.d || lhs.d->isEmpty();
3083 bool thatIsEmpty = !rhs.d || rhs.d->isEmpty();
3084
3085 // sort an empty URL first
3086 if (thisIsEmpty) {
3087 if (!thatIsEmpty)
3089 else
3091 } else {
3093 }
3094 }
3095
3096 int cmp;
3097 cmp = lhs.d->scheme.compare(rhs.d->scheme);
3098 if (cmp != 0)
3099 return Qt::compareThreeWay(cmp, 0);
3100
3101 cmp = lhs.d->userName.compare(rhs.d->userName);
3102 if (cmp != 0)
3103 return Qt::compareThreeWay(cmp, 0);
3104
3105 cmp = lhs.d->password.compare(rhs.d->password);
3106 if (cmp != 0)
3107 return Qt::compareThreeWay(cmp, 0);
3108
3109 cmp = lhs.d->host.compare(rhs.d->host);
3110 if (cmp != 0)
3111 return Qt::compareThreeWay(cmp, 0);
3112
3113 if (lhs.d->port != rhs.d->port)
3114 return Qt::compareThreeWay(lhs.d->port, rhs.d->port);
3115
3116 cmp = lhs.d->path.compare(rhs.d->path);
3117 if (cmp != 0)
3118 return Qt::compareThreeWay(cmp, 0);
3119
3120 if (lhs.d->hasQuery() != rhs.d->hasQuery())
3122
3123 cmp = lhs.d->query.compare(rhs.d->query);
3124 if (cmp != 0)
3125 return Qt::compareThreeWay(cmp, 0);
3126
3127 if (lhs.d->hasFragment() != rhs.d->hasFragment())
3129
3130 cmp = lhs.d->fragment.compare(rhs.d->fragment);
3131 return Qt::compareThreeWay(cmp, 0);
3132}
3133
3143bool comparesEqual(const QUrl &lhs, const QUrl &rhs)
3144{
3145 if (!lhs.d && !rhs.d)
3146 return true;
3147 if (!lhs.d)
3148 return rhs.d->isEmpty();
3149 if (!rhs.d)
3150 return lhs.d->isEmpty();
3151
3152 // First, compare which sections are present, since it speeds up the
3153 // processing considerably. We just have to ignore the host-is-present flag
3154 // for local files (the "file" protocol), due to the requirements of the
3155 // XDG file URI specification.
3157 if (lhs.isLocalFile())
3158 mask &= ~QUrlPrivate::Host;
3159 return (lhs.d->sectionIsPresent & mask) == (rhs.d->sectionIsPresent & mask) &&
3160 lhs.d->scheme == rhs.d->scheme &&
3161 lhs.d->userName == rhs.d->userName &&
3162 lhs.d->password == rhs.d->password &&
3163 lhs.d->host == rhs.d->host &&
3164 lhs.d->port == rhs.d->port &&
3165 lhs.d->path == rhs.d->path &&
3166 lhs.d->query == rhs.d->query &&
3167 lhs.d->fragment == rhs.d->fragment;
3168}
3169
3180bool QUrl::matches(const QUrl &url, FormattingOptions options) const
3181{
3182 if (!d && !url.d)
3183 return true;
3184 if (!d)
3185 return url.d->isEmpty();
3186 if (!url.d)
3187 return d->isEmpty();
3188
3189 // First, compare which sections are present, since it speeds up the
3190 // processing considerably. We just have to ignore the host-is-present flag
3191 // for local files (the "file" protocol), due to the requirements of the
3192 // XDG file URI specification.
3194 if (isLocalFile())
3195 mask &= ~QUrlPrivate::Host;
3196
3197 if (options.testFlag(QUrl::RemoveScheme))
3198 mask &= ~QUrlPrivate::Scheme;
3199 else if (d->scheme != url.d->scheme)
3200 return false;
3201
3202 if (options.testFlag(QUrl::RemovePassword))
3203 mask &= ~QUrlPrivate::Password;
3204 else if (d->password != url.d->password)
3205 return false;
3206
3207 if (options.testFlag(QUrl::RemoveUserInfo))
3208 mask &= ~QUrlPrivate::UserName;
3209 else if (d->userName != url.d->userName)
3210 return false;
3211
3212 if (options.testFlag(QUrl::RemovePort))
3213 mask &= ~QUrlPrivate::Port;
3214 else if (d->port != url.d->port)
3215 return false;
3216
3217 if (options.testFlag(QUrl::RemoveAuthority))
3218 mask &= ~QUrlPrivate::Host;
3219 else if (d->host != url.d->host)
3220 return false;
3221
3222 if (options.testFlag(QUrl::RemoveQuery))
3223 mask &= ~QUrlPrivate::Query;
3224 else if (d->query != url.d->query)
3225 return false;
3226
3227 if (options.testFlag(QUrl::RemoveFragment))
3229 else if (d->fragment != url.d->fragment)
3230 return false;
3231
3232 if ((d->sectionIsPresent & mask) != (url.d->sectionIsPresent & mask))
3233 return false;
3234
3235 if (options.testFlag(QUrl::RemovePath))
3236 return true;
3237
3238 // Compare paths, after applying path-related options
3239 QString path1;
3240 d->appendPath(path1, options, QUrlPrivate::Path);
3241 QString path2;
3242 url.d->appendPath(path2, options, QUrlPrivate::Path);
3243 return path1 == path2;
3244}
3245
3259{
3260 if (!d) {
3261 if (url.d) {
3262 url.d->ref.ref();
3263 d = url.d;
3264 }
3265 } else {
3266 if (url.d)
3267 qAtomicAssign(d, url.d);
3268 else
3269 clear();
3270 }
3271 return *this;
3272}
3273
3278{
3279 if (url.isEmpty()) {
3280 clear();
3281 } else {
3282 detach();
3283 d->parse(url, TolerantMode);
3284 }
3285 return *this;
3286}
3287
3302{
3303 if (!d)
3304 d = new QUrlPrivate;
3305 else
3306 qAtomicDetach(d);
3307}
3308
3313{
3314 return !d || d->ref.loadRelaxed() == 1;
3315}
3316
3317static QString fromNativeSeparators(const QString &pathName)
3318{
3319#if defined(Q_OS_WIN)
3320 QString result(pathName);
3321 const QChar nativeSeparator = u'\\';
3322 auto i = result.indexOf(nativeSeparator);
3323 if (i != -1) {
3324 QChar * const data = result.data();
3325 const auto length = result.length();
3326 for (; i < length; ++i) {
3327 if (data[i] == nativeSeparator)
3328 data[i] = u'/';
3329 }
3330 }
3331 return result;
3332#else
3333 return pathName;
3334#endif
3335}
3336
3369{
3370 QUrl url;
3371 if (localFile.isEmpty())
3372 return url;
3374 QString deslashified = fromNativeSeparators(localFile);
3375
3376 // magic for drives on windows
3377 if (deslashified.size() > 1 && deslashified.at(1) == u':' && deslashified.at(0) != u'/') {
3378 deslashified.prepend(u'/');
3379 } else if (deslashified.startsWith("//"_L1)) {
3380 // magic for shared drive on windows
3381 qsizetype indexOfPath = deslashified.indexOf(u'/', 2);
3382 QStringView hostSpec = QStringView{deslashified}.mid(2, indexOfPath - 2);
3383 // Check for Windows-specific WebDAV specification: "//host@SSL/path".
3384 if (hostSpec.endsWith(webDavSslTag(), Qt::CaseInsensitive)) {
3385 hostSpec.truncate(hostSpec.size() - 4);
3386 scheme = webDavScheme();
3387 }
3388
3389 // hosts can't be IPv6 addresses without [], so we can use QUrlPrivate::setHost
3390 url.detach();
3391 if (!url.d->setHost(hostSpec.toString(), 0, hostSpec.size(), StrictMode)) {
3393 return url;
3394
3395 // Path hostname is not a valid URL host, so set it entirely in the path
3396 // (by leaving deslashified unchanged)
3397 } else if (indexOfPath > 2) {
3398 deslashified = deslashified.right(deslashified.size() - indexOfPath);
3399 } else {
3400 deslashified.clear();
3401 }
3402 }
3403
3405 url.setPath(deslashified, DecodedMode);
3406 return url;
3407}
3408
3426{
3427 // the call to isLocalFile() also ensures that we're parsed
3428 if (!isLocalFile())
3429 return QString();
3430
3432}
3433
3446{
3447 return d && d->isLocalFile();
3448}
3449
3455bool QUrl::isParentOf(const QUrl &childUrl) const
3456{
3457 QString childPath = childUrl.path();
3458
3459 if (!d)
3460 return ((childUrl.scheme().isEmpty())
3461 && (childUrl.authority().isEmpty())
3462 && childPath.size() > 0 && childPath.at(0) == u'/');
3463
3464 QString ourPath = path();
3465
3466 return ((childUrl.scheme().isEmpty() || d->scheme == childUrl.scheme())
3467 && (childUrl.authority().isEmpty() || authority() == childUrl.authority())
3468 && childPath.startsWith(ourPath)
3469 && ((ourPath.endsWith(u'/') && childPath.size() > ourPath.size())
3470 || (!ourPath.endsWith(u'/') && childPath.size() > ourPath.size()
3471 && childPath.at(ourPath.size()) == u'/')));
3472}
3473
3474
3475#ifndef QT_NO_DATASTREAM
3484{
3485 QByteArray u;
3486 if (url.isValid())
3487 u = url.toEncoded();
3488 out << u;
3489 return out;
3490}
3491
3500{
3501 QByteArray u;
3502 in >> u;
3504 return in;
3505}
3506#endif // QT_NO_DATASTREAM
3507
3508#ifndef QT_NO_DEBUG_STREAM
3510{
3511 QDebugStateSaver saver(d);
3512 d.nospace() << "QUrl(" << url.toDisplayString() << ')';
3513 return d;
3514}
3515#endif
3516
3517static QString errorMessage(QUrlPrivate::ErrorCode errorCode, const QString &errorSource, qsizetype errorPosition)
3518{
3519 QChar c = size_t(errorPosition) < size_t(errorSource.size()) ?
3520 errorSource.at(errorPosition) : QChar(QChar::Null);
3521
3522 switch (errorCode) {
3524 Q_UNREACHABLE_RETURN(QString()); // QUrl::errorString should have treated this condition
3525
3527 auto msg = "Invalid scheme (character '%1' not permitted)"_L1;
3528 return msg.arg(c);
3529 }
3530
3532 return "Invalid user name (character '%1' not permitted)"_L1
3533 .arg(c);
3534
3536 return "Invalid password (character '%1' not permitted)"_L1
3537 .arg(c);
3538
3540 if (errorPosition >= 0)
3541 return "Invalid hostname (character '%1' not permitted)"_L1
3542 .arg(c);
3543 else
3544 return QStringLiteral("Invalid hostname (contains invalid characters)");
3546 return QString(); // doesn't happen yet
3548 return QStringLiteral("Invalid IPv6 address");
3550 return "Invalid IPv6 address (character '%1' not permitted)"_L1.arg(c);
3552 return "Invalid IPvFuture address (character '%1' not permitted)"_L1.arg(c);
3554 return QStringLiteral("Expected ']' to match '[' in hostname");
3555
3557 return QStringLiteral("Invalid port or port number out of range");
3559 return QStringLiteral("Port field was empty");
3560
3562 return "Invalid path (character '%1' not permitted)"_L1
3563 .arg(c);
3564
3566 return "Invalid query (character '%1' not permitted)"_L1
3567 .arg(c);
3568
3570 return "Invalid fragment (character '%1' not permitted)"_L1
3571 .arg(c);
3572
3574 return QStringLiteral("Path component is relative and authority is present");
3576 return QStringLiteral("Path component starts with '//' and authority is absent");
3578 return QStringLiteral("Relative URL's path component contains ':' before any '/'");
3579 }
3580
3581 Q_UNREACHABLE_RETURN(QString());
3582}
3583
3584static inline void appendComponentIfPresent(QString &msg, bool present, const char *componentName,
3585 const QString &component)
3586{
3587 if (present)
3588 msg += QLatin1StringView(componentName) % u'"' % component % "\","_L1;
3589}
3590
3605{
3606 QString msg;
3607 if (!d)
3608 return msg;
3609
3610 QString errorSource;
3611 qsizetype errorPosition = 0;
3612 QUrlPrivate::ErrorCode errorCode = d->validityError(&errorSource, &errorPosition);
3613 if (errorCode == QUrlPrivate::NoError)
3614 return msg;
3615
3616 msg += errorMessage(errorCode, errorSource, errorPosition);
3617 msg += "; source was \""_L1;
3618 msg += errorSource;
3619 msg += "\";"_L1;
3621 " scheme = ", d->scheme);
3623 " userinfo = ", userInfo());
3625 " host = ", d->host);
3626 appendComponentIfPresent(msg, d->port != -1,
3627 " port = ", QString::number(d->port));
3629 " path = ", d->path);
3631 " query = ", d->query);
3633 " fragment = ", d->fragment);
3634 if (msg.endsWith(u','))
3635 msg.chop(1);
3636 return msg;
3637}
3638
3644QStringList QUrl::toStringList(const QList<QUrl> &urls, FormattingOptions options)
3645{
3646 QStringList lst;
3647 lst.reserve(urls.size());
3648 for (const QUrl &url : urls)
3649 lst.append(url.toString(options));
3650 return lst;
3651
3652}
3653
3661{
3662 QList<QUrl> lst;
3663 lst.reserve(urls.size());
3664 for (const QString &str : urls)
3665 lst.append(QUrl(str, mode));
3666 return lst;
3667}
3668
3686size_t qHash(const QUrl &url, size_t seed) noexcept
3687{
3688 if (!url.d)
3689 return qHash(-1, seed); // the hash of an unset port (-1)
3690
3691 return qHash(url.d->scheme) ^
3692 qHash(url.d->userName) ^
3693 qHash(url.d->password) ^
3694 qHash(url.d->host) ^
3695 qHash(url.d->port, seed) ^
3696 qHash(url.d->path) ^
3697 qHash(url.d->query) ^
3698 qHash(url.d->fragment);
3699}
3700
3702{
3703 if (url.scheme() == ftpScheme()) {
3705 if (path.startsWith("//"_L1))
3707 }
3708 return url;
3709}
3710
3711static bool isIp6(const QString &text)
3712{
3714 return !text.isEmpty() && QIPAddressUtils::parseIp6(address, text.begin(), text.end()) == nullptr;
3715}
3716
3757QUrl QUrl::fromUserInput(const QString &userInput, const QString &workingDirectory,
3758 UserInputResolutionOptions options)
3759{
3760 QString trimmedString = userInput.trimmed();
3761
3762 if (trimmedString.isEmpty())
3763 return QUrl();
3764
3765 // Check for IPv6 addresses, since a path starting with ":" is absolute (a resource)
3766 // and IPv6 addresses can start with "c:" too
3767 if (isIp6(trimmedString)) {
3768 QUrl url;
3769 url.setHost(trimmedString);
3770 url.setScheme(QStringLiteral("http"));
3771 return url;
3772 }
3773
3774 const QUrl url = QUrl(trimmedString, QUrl::TolerantMode);
3775
3776 // Check for a relative path
3777 if (!workingDirectory.isEmpty()) {
3778 const QFileInfo fileInfo(QDir(workingDirectory), userInput);
3779 if (fileInfo.exists())
3780 return QUrl::fromLocalFile(fileInfo.absoluteFilePath());
3781
3782 // Check both QUrl::isRelative (to detect full URLs) and QDir::isAbsolutePath (since on Windows drive letters can be interpreted as schemes)
3783 if ((options & AssumeLocalFile) && url.isRelative() && !QDir::isAbsolutePath(userInput))
3784 return QUrl::fromLocalFile(fileInfo.absoluteFilePath());
3785 }
3786
3787 // Check first for files, since on Windows drive letters can be interpreted as schemes
3788 if (QDir::isAbsolutePath(trimmedString))
3789 return QUrl::fromLocalFile(trimmedString);
3790
3791 QUrl urlPrepended = QUrl("http://"_L1 + trimmedString, QUrl::TolerantMode);
3792
3793 // Check the most common case of a valid url with a scheme
3794 // We check if the port would be valid by adding the scheme to handle the case host:port
3795 // where the host would be interpreted as the scheme
3796 if (url.isValid()
3797 && !url.scheme().isEmpty()
3798 && urlPrepended.port() == -1)
3799 return adjustFtpPath(url);
3800
3801 // Else, try the prepended one and adjust the scheme from the host name
3802 if (urlPrepended.isValid() && (!urlPrepended.host().isEmpty() || !urlPrepended.path().isEmpty())) {
3803 qsizetype dotIndex = trimmedString.indexOf(u'.');
3804 const QStringView hostscheme = QStringView{trimmedString}.left(dotIndex);
3805 if (hostscheme.compare(ftpScheme(), Qt::CaseInsensitive) == 0)
3806 urlPrepended.setScheme(ftpScheme());
3807 return adjustFtpPath(urlPrepended);
3808 }
3809
3810 return QUrl();
3811}
3812
\inmodule QtCore
Definition qatomic.h:112
bool ref() noexcept
bool deref() noexcept
T loadRelaxed() const noexcept
\inmodule QtCore
Definition qbytearray.h:57
qsizetype size() const noexcept
Returns the number of bytes in this byte array.
Definition qbytearray.h:494
static QByteArray fromPercentEncoding(const QByteArray &pctEncoded, char percent='%')
\inmodule QtCore
\inmodule QtCore\reentrant
Definition qdatastream.h:46
\inmodule QtCore
\inmodule QtCore
@ DefaultNormalization
Definition qdir_p.h:31
@ RemotePath
Definition qdir_p.h:33
\inmodule QtCore
Definition qdir.h:20
static bool isAbsolutePath(const QString &path)
Returns true if path is absolute; returns false if it is relative.
Definition qdir.h:184
QString absoluteFilePath() const
bool exists() const
Returns true if the file system entry this QFileInfo refers to exists; otherwise returns false.
size_t qHash(const QUrl &url, size_t seed) noexcept
Returns the hash value for the url.
Definition qurl.cpp:3686
Represents an immutable JsonPath like path in the Qml code model (from a DomItem to another DomItem)
\inmodule QtCore
\inmodule QtCore
Definition qstringview.h:78
constexpr void truncate(qsizetype n) noexcept
Truncates this string view to length length.
constexpr bool isEmpty() const noexcept
Returns whether this string view is empty - that is, whether {size() == 0}.
const_iterator constEnd() const noexcept
constexpr QStringView left(qsizetype n) const noexcept
constexpr QStringView mid(qsizetype pos, qsizetype n=-1) const noexcept
Returns the substring of length length starting at position start in this object.
const_iterator constBegin() const noexcept
qsizetype lastIndexOf(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
qsizetype indexOf(QChar c, qsizetype from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
QString left(qsizetype n) const &
Definition qstring.h:363
iterator begin()
Returns an \l{STL-style iterators}{STL-style iterator} pointing to the first character in the string.
Definition qstring.h:1349
QByteArray toLatin1() const &
Definition qstring.h:630
qsizetype indexOf(QLatin1StringView s, qsizetype from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition qstring.cpp:4517
const_iterator constEnd() const
Returns a const \l{STL-style iterators}{STL-style iterator} pointing just after the last character in...
Definition qstring.h:1363
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition qstring.cpp:5455
void reserve(qsizetype size)
Ensures the string has space for at least size characters.
Definition qstring.h:1325
void chop(qsizetype n)
Removes n characters from the end of the string.
Definition qstring.cpp:6340
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:5871
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
Definition qstring.h:192
void clear()
Clears the contents of the string and makes it null.
Definition qstring.h:1252
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition qstring.h:994
qsizetype size() const noexcept
Returns the number of characters in this string.
Definition qstring.h:186
static QString fromUtf8(QByteArrayView utf8)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:6018
iterator end()
Returns an \l{STL-style iterators}{STL-style iterator} pointing just after the last character in the ...
Definition qstring.h:1357
void detach()
Definition qstring.h:1248
const QChar at(qsizetype i) const
Returns the character at the given index position in the string.
Definition qstring.h:1226
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string ends with s; otherwise returns false.
Definition qstring.cpp:5506
int compare(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
Definition qstring.cpp:6664
QChar * data()
Returns a pointer to the data stored in the QString.
Definition qstring.h:1240
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:8084
QString trimmed() const &
Definition qstring.h:447
QString & remove(qsizetype i, qsizetype len)
Removes n characters from the string, starting at the given position index, and returns a reference t...
Definition qstring.cpp:3466
const_iterator constBegin() const
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first character in the st...
Definition qstring.h:1355
bool isEmpty() const
Definition qurl.cpp:507
void setQuery(const QString &value, qsizetype from, qsizetype end)
Definition qurl.cpp:1121
QAtomicInt ref
Definition qurl.cpp:555
void appendPassword(QString &appendTo, QUrl::FormattingOptions options) const
Definition qurl.cpp:903
bool hasScheme() const
Definition qurl.cpp:539
void setUserInfo(const QString &userInfo, qsizetype from, qsizetype end)
Definition qurl.cpp:1084
void appendHost(QString &appendTo, QUrl::FormattingOptions options) const
Definition qurl.cpp:1157
void setPath(const QString &value, qsizetype from, qsizetype end)
Definition qurl.cpp:1109
bool validateComponent(Section section, const QString &input, qsizetype begin, qsizetype end)
Definition qurl.cpp:1674
QString host
Definition qurl.cpp:561
uchar sectionIsPresent
Definition qurl.cpp:572
std::unique_ptr< Error > cloneError() const
Definition qurl.cpp:604
void setAuthority(const QString &auth, qsizetype from, qsizetype end, QUrl::ParsingMode mode)
Definition qurl.cpp:1014
bool hasPort() const
Definition qurl.cpp:545
QString toLocalFile(QUrl::FormattingOptions options) const
Definition qurl.cpp:1470
std::unique_ptr< Error > error
Definition qurl.cpp:566
ErrorCode validityError(QString *source=nullptr, qsizetype *position=nullptr) const
Definition qurl.cpp:1609
bool hasQuery() const
Definition qurl.cpp:547
void setFragment(const QString &value, qsizetype from, qsizetype end)
Definition qurl.cpp:1115
bool hasUserInfo() const
Definition qurl.cpp:541
QString mergePaths(const QString &relativePath) const
Definition qurl.cpp:1505
bool isLocalFile() const
Definition qurl.cpp:550
@ InvalidIPv6AddressError
Definition qurl.cpp:473
@ InvalidIPv4AddressError
Definition qurl.cpp:472
@ InvalidCharacterInIPv6Error
Definition qurl.cpp:474
@ InvalidPasswordError
Definition qurl.cpp:469
@ InvalidPathError
Definition qurl.cpp:481
@ InvalidSchemeError
Definition qurl.cpp:465
@ InvalidIPvFutureError
Definition qurl.cpp:475
@ InvalidUserNameError
Definition qurl.cpp:467
@ PortEmptyError
Definition qurl.cpp:479
@ InvalidFragmentError
Definition qurl.cpp:485
@ AuthorityPresentAndPathIsRelative
Definition qurl.cpp:489
@ AuthorityAbsentAndPathIsDoubleSlash
Definition qurl.cpp:490
@ InvalidPortError
Definition qurl.cpp:478
@ RelativeUrlPathContainsColonBeforeSlash
Definition qurl.cpp:491
@ InvalidRegNameError
Definition qurl.cpp:471
@ InvalidQueryError
Definition qurl.cpp:483
@ HostMissingEndBracket
Definition qurl.cpp:476
QString path
Definition qurl.cpp:562
bool hasPath() const
Definition qurl.cpp:546
QUrlPrivate()
Definition qurl.cpp:579
void clearError()
Definition qurl.cpp:609
bool setScheme(const QString &value, qsizetype len, bool doSetError)
Definition qurl.cpp:949
void appendAuthority(QString &appendTo, QUrl::FormattingOptions options, Section appendingTo) const
Definition qurl.cpp:837
uchar flags
Definition qurl.cpp:573
@ IsLocalFile
Definition qurl.cpp:459
QString scheme
Definition qurl.cpp:558
void appendUserName(QString &appendTo, QUrl::FormattingOptions options) const
Definition qurl.cpp:896
void appendUserInfo(QString &appendTo, QUrl::FormattingOptions options, Section appendingTo) const
Definition qurl.cpp:851
bool hasFragment() const
Definition qurl.cpp:548
void setPassword(const QString &value, qsizetype from, qsizetype end)
Definition qurl.cpp:1103
void appendPath(QString &appendTo, QUrl::FormattingOptions options, Section appendingTo) const
Definition qurl.cpp:910
bool validateComponent(Section section, const QString &input)
Definition qurl.cpp:515
void setError(ErrorCode errorCode, const QString &source, qsizetype supplement=-1)
Definition qurl.cpp:614
bool hasUserName() const
Definition qurl.cpp:542
QString fragment
Definition qurl.cpp:564
QString query
Definition qurl.cpp:563
QString userName
Definition qurl.cpp:559
bool hasAuthority() const
Definition qurl.cpp:540
bool hasHost() const
Definition qurl.cpp:544
void appendQuery(QString &appendTo, QUrl::FormattingOptions options, Section appendingTo) const
Definition qurl.cpp:941
QString password
Definition qurl.cpp:560
void appendFragment(QString &appendTo, QUrl::FormattingOptions options, Section appendingTo) const
Definition qurl.cpp:934
bool setHost(const QString &value, qsizetype from, qsizetype end, QUrl::ParsingMode mode)
Definition qurl.cpp:1274
bool hasPassword() const
Definition qurl.cpp:543
void setUserName(const QString &value, qsizetype from, qsizetype end)
Definition qurl.cpp:1097
void parse(const QString &url, QUrl::ParsingMode parsingMode)
Definition qurl.cpp:1367
\inmodule QtCore
Definition qurlquery.h:20
constexpr bool testFlag(E1 f) const
Definition qurl.h:82
\inmodule QtCore
Definition qurl.h:94
static QUrl fromLocalFile(const QString &localfile)
Returns a QUrl representation of localFile, interpreted as a local file.
Definition qurl.cpp:3368
QString userInfo(ComponentFormattingOptions options=PrettyDecoded) const
Returns the user info of the URL, or an empty string if the user info is undefined.
Definition qurl.cpp:2129
bool hasQuery() const
Definition qurl.cpp:2513
static QList< QUrl > fromStringList(const QStringList &uris, ParsingMode mode=TolerantMode)
Definition qurl.cpp:3660
QString fragment(ComponentFormattingOptions options=PrettyDecoded) const
Returns the fragment of the URL.
Definition qurl.cpp:2682
QUrl()
Constructs an empty QUrl object.
Definition qurl.cpp:1851
bool matches(const QUrl &url, FormattingOptions options) const
Definition qurl.cpp:3180
bool isLocalFile() const
Definition qurl.cpp:3445
QString url(FormattingOptions options=FormattingOptions(PrettyDecoded)) const
Returns a string representation of the URL.
Definition qurl.cpp:2817
QString query(ComponentFormattingOptions=PrettyDecoded) const
Returns the query string of the URL if there's a query string, or an empty result if not.
Definition qurl.cpp:2609
static QByteArray toAce(const QString &domain, AceProcessingOptions options={})
Definition qurl.cpp:3064
QString fileName(ComponentFormattingOptions options=FullyDecoded) const
Definition qurl.cpp:2497
static QStringList toStringList(const QList< QUrl > &uris, FormattingOptions options=FormattingOptions(PrettyDecoded))
Definition qurl.cpp:3644
QUrl resolved(const QUrl &relative) const
Returns the result of the merge of this URL with relative.
Definition qurl.cpp:2725
void setPassword(const QString &password, ParsingMode mode=DecodedMode)
Sets the URL's password to password.
Definition qurl.cpp:2227
void setUserName(const QString &userName, ParsingMode mode=DecodedMode)
Sets the URL's user name to userName.
Definition qurl.cpp:2164
void setFragment(const QString &fragment, ParsingMode mode=TolerantMode)
Sets the fragment of the URL to fragment.
Definition qurl.cpp:2648
bool hasFragment() const
Definition qurl.cpp:2700
static QString fromPercentEncoding(const QByteArray &)
Returns a decoded copy of input.
Definition qurl.cpp:3001
bool isRelative() const
Returns true if the URL is relative; otherwise returns false.
Definition qurl.cpp:2800
bool isDetached() const
Definition qurl.cpp:3312
bool isValid() const
Returns true if the URL is non-empty and valid; otherwise returns false.
Definition qurl.cpp:1882
~QUrl()
Destructor; called immediately before the object is deleted.
Definition qurl.cpp:1867
QString userName(ComponentFormattingOptions options=FullyDecoded) const
Returns the user name of the URL if it is defined; otherwise an empty string is returned.
Definition qurl.cpp:2199
QString host(ComponentFormattingOptions=FullyDecoded) const
Returns the host of the URL if it is defined; otherwise an empty string is returned.
Definition qurl.cpp:2340
void setQuery(const QString &query, ParsingMode mode=TolerantMode)
Sets the query string of the URL to query.
Definition qurl.cpp:2550
static QUrl fromUserInput(const QString &userInput, const QString &workingDirectory=QString(), UserInputResolutionOptions options=DefaultResolution)
Returns a valid URL from a user supplied userInput string if one can be deduced.
Definition qurl.cpp:3757
@ AssumeLocalFile
Definition qurl.h:175
void detach()
Definition qurl.cpp:3301
QByteArray toEncoded(FormattingOptions options=FullyEncoded) const
Returns the encoded representation of the URL if it's valid; otherwise an empty QByteArray is returne...
Definition qurl.cpp:2967
QString password(ComponentFormattingOptions=FullyDecoded) const
Returns the password of the URL if it is defined; otherwise an empty string is returned.
Definition qurl.cpp:2262
ParsingMode
The parsing mode controls the way QUrl parses strings.
Definition qurl.h:96
@ DecodedMode
Definition qurl.h:99
@ TolerantMode
Definition qurl.h:97
@ StrictMode
Definition qurl.h:98
bool isEmpty() const
Returns true if the URL has no data; otherwise returns false.
Definition qurl.cpp:1896
static QByteArray toPercentEncoding(const QString &, const QByteArray &exclude=QByteArray(), const QByteArray &include=QByteArray())
Returns an encoded copy of input.
Definition qurl.cpp:3019
void setUrl(const QString &url, ParsingMode mode=TolerantMode)
Parses url and sets this object to that value.
Definition qurl.cpp:1934
QString authority(ComponentFormattingOptions options=PrettyDecoded) const
Returns the authority of the URL if it is defined; otherwise an empty string is returned.
Definition qurl.cpp:2055
bool isParentOf(const QUrl &url) const
Returns true if this URL is a parent of childUrl.
Definition qurl.cpp:3455
QUrl adjusted(FormattingOptions options) const
Definition qurl.cpp:2924
QString scheme() const
Returns the scheme of the URL.
Definition qurl.cpp:1991
void setScheme(const QString &scheme)
Sets the scheme of the URL to scheme.
Definition qurl.cpp:1967
void clear()
Resets the content of the QUrl.
Definition qurl.cpp:1909
QString errorString() const
Definition qurl.cpp:3604
@ RemovePassword
Definition qurl.h:106
@ RemoveScheme
Definition qurl.h:105
@ StripTrailingSlash
Definition qurl.h:115
@ RemoveFragment
Definition qurl.h:112
@ RemoveQuery
Definition qurl.h:111
@ RemoveFilename
Definition qurl.h:116
@ PreferLocalFile
Definition qurl.h:114
@ NormalizePathSegments
Definition qurl.h:117
@ RemovePath
Definition qurl.h:110
@ RemoveUserInfo
Definition qurl.h:107
@ RemoveAuthority
Definition qurl.h:109
@ RemovePort
Definition qurl.h:108
static QString fromAce(const QByteArray &domain, AceProcessingOptions options={})
Definition qurl.cpp:3041
void setHost(const QString &host, ParsingMode mode=DecodedMode)
Sets the host of the URL to host.
Definition qurl.cpp:2289
int port(int defaultPort=-1) const
Definition qurl.cpp:2383
void setAuthority(const QString &authority, ParsingMode mode=TolerantMode)
Sets the authority of the URL to authority.
Definition qurl.cpp:2027
@ PrettyDecoded
Definition qurl.h:121
@ EncodeReserved
Definition qurl.h:125
@ FullyDecoded
Definition qurl.h:130
@ EncodeDelimiters
Definition qurl.h:124
@ EncodeUnicode
Definition qurl.h:123
@ DecodeReserved
Definition qurl.h:126
@ FullyEncoded
Definition qurl.h:129
QDataStream & operator>>(QDataStream &in, QUrl &url)
Reads a url into url from the stream in and returns a reference to the stream.
Definition qurl.cpp:3499
void setUserInfo(const QString &userInfo, ParsingMode mode=TolerantMode)
Sets the user info of the URL to userInfo.
Definition qurl.cpp:2093
void setPath(const QString &path, ParsingMode mode=DecodedMode)
Sets the path of the URL to path.
Definition qurl.cpp:2414
QString toDisplayString(FormattingOptions options=FormattingOptions(PrettyDecoded)) const
Definition qurl.cpp:2906
QUrl & operator=(const QUrl &copy) noexcept
Assigns the specified url to this object.
Definition qurl.cpp:3258
static QUrl fromEncoded(QByteArrayView input, ParsingMode mode=TolerantMode)
Parses input and returns the corresponding QUrl.
Definition qurl.cpp:2988
QString toString(FormattingOptions options=FormattingOptions(PrettyDecoded)) const
Returns a string representation of the URL.
Definition qurl.cpp:2831
void setPort(int port)
Sets the port of the URL to port.
Definition qurl.cpp:2358
QDataStream & operator<<(QDataStream &out, const QUrl &url)
Writes url url to the stream out and returns a reference to the stream.
Definition qurl.cpp:3483
QString toLocalFile() const
Returns the path of this URL formatted as a local file path.
Definition qurl.cpp:3425
QString path(ComponentFormattingOptions options=FullyDecoded) const
Returns the path of the URL.
Definition qurl.cpp:2468
\variable Qt::strong_ordering::less
Definition qcompare.h:221
static const weak_ordering less
Definition qcompare.h:223
static const weak_ordering greater
Definition qcompare.h:225
static const weak_ordering equivalent
Definition qcompare.h:224
QHash< int, QWidget * > hash
[35multi]
QString str
[2]
b clear()
QString text
void setHost()
quint8 IPv6Address[16]
void toString(QString &appendTo, IPv4Address address)
bool parseIp4(IPv4Address &address, const QChar *begin, const QChar *end)
quint32 IPv4Address
const QChar * parseIp6(IPv6Address &address, const QChar *begin, const QChar *end)
Combined button and popup list for selecting options.
constexpr bool isAsciiDigit(char32_t c) noexcept
Definition qtools_p.h:67
constexpr bool isAsciiLower(char32_t c) noexcept
Definition qtools_p.h:77
constexpr bool isAsciiLetterOrNumber(char32_t c) noexcept
Definition qtools_p.h:82
constexpr bool isAsciiUpper(char32_t c) noexcept
Definition qtools_p.h:72
constexpr bool isHexDigit(char32_t c) noexcept
Definition qtools_p.h:37
constexpr Qt::strong_ordering compareThreeWay(LeftInt lhs, RightInt rhs) noexcept
@ CaseInsensitive
static jboolean copy(JNIEnv *, jobject)
QT_WARNING_POP void qAtomicAssign(T *&d, T *x)
This is a helper for the assignment operators of implicitly shared classes.
Definition qatomic.h:180
void qAtomicDetach(T *&d)
This is a helper for the detach method of implicitly shared classes.
Definition qatomic.h:199
#define Q_LIKELY(x)
DBusConnection const char DBusError * error
QString qt_normalizePathSegments(const QString &name, QDirPrivate::PathNormalizations flags, bool *ok)
Definition qdir.cpp:2207
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
EGLOutputPortEXT port
size_t qHash(const QFileSystemWatcherPathKey &key, size_t seed=0)
#define qDebug
[1]
Definition qlogging.h:164
#define qWarning
Definition qlogging.h:166
return ret
GLint GLint GLint GLint GLint x
[0]
GLenum mode
GLuint GLuint end
GLenum GLuint GLenum GLsizei length
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLbitfield flags
GLint ref
GLint GLint GLint GLint GLint GLint GLint GLbitfield mask
GLsizei GLsizei GLchar * source
GLdouble s
[6]
Definition qopenglext.h:235
GLenum query
const GLubyte * c
GLdouble GLdouble t
Definition qopenglext.h:243
GLuint in
GLuint GLuint64EXT address
GLsizei const GLchar *const * path
GLuint64EXT * result
[6]
GLfloat GLfloat p
[1]
GLenum GLsizei len
GLenum GLenum GLenum input
static qreal component(const QPointF &point, unsigned int i)
static qreal position(const QQuickItem *item, QQuickAnchors::Anchor anchorLine)
static Q_CONSTINIT QBasicAtomicInteger< unsigned > seed
Definition qrandom.cpp:196
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
QtPrivate::QRegularExpressionMatchIteratorRangeBasedForIterator begin(const QRegularExpressionMatchIterator &iterator)
#define qUtf16Printable(string)
Definition qstring.h:1543
#define QStringLiteral(str)
ErrorCode
Definition main.cpp:3324
#define QT_TRANSLATE_NOOP(scope, x)
unsigned char uchar
Definition qtypes.h:32
unsigned long ulong
Definition qtypes.h:35
ptrdiff_t qsizetype
Definition qtypes.h:165
unsigned int uint
Definition qtypes.h:34
unsigned short ushort
Definition qtypes.h:33
static const ushort *const passwordInIsolation
Definition qurl.cpp:739
static const ushort *const pathInUrl
Definition qurl.cpp:799
static QString recodeFromUser(const QString &input, const ushort *actions, qsizetype from, qsizetype to)
Definition qurl.cpp:809
static const ushort userNameInUrl[]
Definition qurl.cpp:786
QDebug operator<<(QDebug d, const QUrl &url)
Definition qurl.cpp:3509
static QString fileScheme()
Definition qurl.cpp:425
static const ushort *const pathInIsolation
Definition qurl.cpp:740
static const QChar * parseIpFuture(QString &host, const QChar *begin, const QChar *end, QUrl::ParsingMode mode)
Definition qurl.cpp:1182
static void appendComponentIfPresent(QString &msg, bool present, const char *componentName, const QString &component)
Definition qurl.cpp:3584
static void removeDotsFromPath(QString *path)
Definition qurl.cpp:1533
static QString webDavSslTag()
Definition qurl.cpp:435
static const ushort *const passwordInUrl
Definition qurl.cpp:798
static const ushort userNameInUserInfo[]
Definition qurl.cpp:744
static QString errorMessage(QUrlPrivate::ErrorCode errorCode, const QString &errorSource, qsizetype errorPosition)
Definition qurl.cpp:3517
static void appendToUser(QString &appendTo, QStringView value, QUrl::FormattingOptions options, const ushort *actions)
Definition qurl.cpp:822
static const ushort *const queryInIsolation
Definition qurl.cpp:741
static bool isHex(char c)
Definition qurl.cpp:414
static const ushort userNameInIsolation[]
Definition qurl.cpp:720
static const QChar * parseIp6(QString &host, const QChar *begin, const QChar *end, QUrl::ParsingMode mode)
Definition qurl.cpp:1227
static const ushort userNameInAuthority[]
Definition qurl.cpp:765
static const ushort *const fragmentInIsolation
Definition qurl.cpp:742
static const ushort *const fragmentInUrl
Definition qurl.cpp:801
Qt::weak_ordering compareThreeWay(const QUrl &lhs, const QUrl &rhs)
Definition qurl.cpp:3079
static QUrl adjustFtpPath(QUrl url)
Definition qurl.cpp:3701
static const ushort *const passwordInAuthority
Definition qurl.cpp:784
static QString ftpScheme()
Definition qurl.cpp:420
static bool isIp6(const QString &text)
Definition qurl.cpp:3711
static const ushort *const queryInUrl
Definition qurl.cpp:800
bool comparesEqual(const QUrl &lhs, const QUrl &rhs)
Definition qurl.cpp:3143
static QString webDavScheme()
Definition qurl.cpp:430
static QString fromNativeSeparators(const QString &pathName)
Definition qurl.cpp:3317
static const ushort *const passwordInUserInfo
Definition qurl.cpp:763
static void parseDecodedComponent(QString &data)
Definition qurl.cpp:803
QT_BEGIN_NAMESPACE Q_AUTOTEST_EXPORT qsizetype qt_urlRecode(QString &appendTo, QStringView url, QUrl::ComponentFormattingOptions encoding, const ushort *tableModifications=nullptr)
@ AllowLeadingDot
Definition qurl_p.h:30
@ ForbidLeadingDot
Definition qurl_p.h:30
QString Q_CORE_EXPORT qt_ACE_do(const QString &domain, AceOperation op, AceLeadingDot dot, QUrl::AceProcessingOptions options={})
Definition qurlidna.cpp:920
@ ToAceOnly
Definition qurl_p.h:31
@ NormalizeAce
Definition qurl_p.h:31
#define decode(x)
#define encode(x)
#define leave(x)
QT_BEGIN_NAMESPACE typedef uchar * output
QByteArray ba
[0]
QTextStream out(stdout)
[7]
QUrl url("example.com")
[constructor-url-reference]
QObject::connect nullptr
QSharedPointer< T > other(t)
[5]
qsizetype position
Definition qurl.cpp:498
ErrorCode code
Definition qurl.cpp:499