| 73 | |
| 74 | |
| 75 | void UBEmbedParser::parse(const QString& html) |
| 76 | { |
| 77 | if (mParsing) |
| 78 | { |
| 79 | // abort any pending network requests for oEmbed information |
| 80 | qDebug() << "abort oembed parsing"; |
| 81 | mParsing = false; |
| 82 | emit cancelled(); |
| 83 | } |
| 84 | |
| 85 | qDebug() << "parse" << html.length() << "bytes"; |
| 86 | mParsing = true; |
| 87 | mContents.clear(); |
| 88 | mParsedTitles.clear(); |
| 89 | |
| 90 | // extract all <link> and <iframe> tags upto but not including the final > |
| 91 | static const QRegularExpression exp("(<|<)(link|iframe)([^>]*)"); |
| 92 | QStringList results; |
| 93 | int count = 0; |
| 94 | QRegularExpressionMatchIterator matches = exp.globalMatch(html); |
| 95 | |
| 96 | while (matches.hasNext()) |
| 97 | { |
| 98 | QRegularExpressionMatch match = matches.next(); |
| 99 | ++count; |
| 100 | QStringList res = match.capturedTexts(); |
| 101 | |
| 102 | if ("" != res.at(0)) |
| 103 | { |
| 104 | results << res.at(0); |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | QList<QString> oembedUrls; |
| 109 | |
| 110 | for (QString result : std::as_const(results)) |
| 111 | { |
| 112 | // replace entities |
| 113 | result = result.trimmed().replace("<", "<").replace(">", ">").replace("\\"", "\"").replace("\\", ""); |
| 114 | |
| 115 | // again cut at first ">" |
| 116 | int greater = result.indexOf('>'); |
| 117 | |
| 118 | if (greater >= 0) |
| 119 | { |
| 120 | result.truncate(greater); |
| 121 | } |
| 122 | |
| 123 | // add trailing slash if necessary |
| 124 | if (result.at(result.length() - 1) != '/') |
| 125 | { |
| 126 | result += "/"; |
| 127 | } |
| 128 | |
| 129 | QString qsNode = result + ">"; |
| 130 | |
| 131 | if (qsNode.startsWith("<iframe")) |
| 132 | { |
no test coverage detected