diff options
author | Topi Reinio <topi.reinio@digia.com> | 2015-04-17 14:57:21 +0200 |
---|---|---|
committer | Topi Reiniƶ <topi.reinio@digia.com> | 2015-04-27 11:44:06 +0000 |
commit | 21c90bcc989cc18ba926cf4dbfbc9d2fce78dd63 (patch) | |
tree | 969d32d27859068a0c9047fc2b4418c92c03f80e /src/tools/qdoc/htmlgenerator.cpp | |
parent | 4dd896785b0b1a3bc6c0fd5380f9b7753fbee9e6 (diff) |
qdoc: Sanitize anchors in URLs for functions
When QDoc constructs the full path to a documentation node, it
must construct a clean anchor reference. Intra-page links use
a different code path, so the links e.g. from Member Functions
list to their detailed descriptions always work, but using the
link command to link to functions with certain characters (such
as 'operator==') failed because the node name was used as-is and
not sanitized ('operator-eq-eq').
This change moves HtmlGenerator::cleanRef() static function to
its parent class, Generator, and takes it into use in
Generator::fullDocumentLocation().
Change-Id: Ic939ffa3ae0f4495ef2a30eff0d4a1de65ea3e8f
Task-number: QTBUG-45629
Reviewed-by: Martin Smith <martin.smith@digia.com>
Diffstat (limited to 'src/tools/qdoc/htmlgenerator.cpp')
-rw-r--r-- | src/tools/qdoc/htmlgenerator.cpp | 57 |
1 files changed, 2 insertions, 55 deletions
diff --git a/src/tools/qdoc/htmlgenerator.cpp b/src/tools/qdoc/htmlgenerator.cpp index f0a23ac65e..710ce08abb 100644 --- a/src/tools/qdoc/htmlgenerator.cpp +++ b/src/tools/qdoc/htmlgenerator.cpp @@ -3355,7 +3355,7 @@ void HtmlGenerator::generateSectionInheritedList(const Section& section, const N out() << section.pluralMember; } out() << " inherited from <a href=\"" << fileName((*p).first) - << '#' << HtmlGenerator::cleanRef(section.name.toLower()) << "\">" + << '#' << Generator::cleanRef(section.name.toLower()) << "\">" << protectEnc((*p).first->plainFullName(relative)) << "</a></li>\n"; ++p; @@ -3610,62 +3610,9 @@ void HtmlGenerator::generateLink(const Atom* atom, CodeMarker* marker) } } -QString HtmlGenerator::cleanRef(const QString& ref) -{ - QString clean; - - if (ref.isEmpty()) - return clean; - - clean.reserve(ref.size() + 20); - const QChar c = ref[0]; - const uint u = c.unicode(); - - if ((u >= 'a' && u <= 'z') || - (u >= 'A' && u <= 'Z') || - (u >= '0' && u <= '9')) { - clean += c; - } else if (u == '~') { - clean += "dtor."; - } else if (u == '_') { - clean += "underscore."; - } else { - clean += QLatin1Char('A'); - } - - for (int i = 1; i < (int) ref.length(); i++) { - const QChar c = ref[i]; - const uint u = c.unicode(); - if ((u >= 'a' && u <= 'z') || - (u >= 'A' && u <= 'Z') || - (u >= '0' && u <= '9') || u == '-' || - u == '_' || u == ':' || u == '.') { - clean += c; - } else if (c.isSpace()) { - clean += QLatin1Char('-'); - } else if (u == '!') { - clean += "-not"; - } else if (u == '&') { - clean += "-and"; - } else if (u == '<') { - clean += "-lt"; - } else if (u == '=') { - clean += "-eq"; - } else if (u == '>') { - clean += "-gt"; - } else if (u == '#') { - clean += QLatin1Char('#'); - } else { - clean += QLatin1Char('-'); - clean += QString::number((int)u, 16); - } - } - return clean; -} - QString HtmlGenerator::registerRef(const QString& ref) { - QString clean = HtmlGenerator::cleanRef(ref); + QString clean = Generator::cleanRef(ref); for (;;) { QString& prevRef = refMap[clean.toLower()]; |