apol added a comment.
Wow that's a lot of code gone! INLINE COMMENTS > packageurlinterceptor.cpp:95 > > - if (d->forcePlasmaStyle && > path.path().contains(QLatin1String("Controls.2/org.kde.desktop/"))) { > - return > QUrl::fromLocalFile(path.path().replace(QLatin1String("Controls.2/org.kde.desktop/"), > QLatin1String("Controls.2/Plasma/"))); > - } > - QString pkgRoot; > - KPackage::Package package; > - if (d->package.isValid()) { > - package = d->package; > - } else { > - foreach (const QString &base, > QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation)) { > - pkgRoot = QFileInfo(base + > QStringLiteral("/plasma/plasmoids/")).canonicalFilePath(); > - if (!pkgRoot.isEmpty() && path.path().startsWith(pkgRoot)) { > - const QString pkgName = path.path().midRef(pkgRoot.length() > + 1).split(QLatin1Char('/')).first().toString(); > - > - auto it = > PackageUrlInterceptorPrivate::s_packages.constFind(pkgName); > - if (it != > PackageUrlInterceptorPrivate::s_packages.constEnd()) { > - package = *it; > - } else { > - package = > Plasma::PluginLoader::self()->loadPackage(QStringLiteral("Plasma/Applet")).kPackage(); > - package.setPath(pkgName); > - PackageUrlInterceptorPrivate::s_packages[pkgName] = > package; > - } > - break; > - } > - } > - } > - if (!package.isValid()) { > - return path; > - } > - > - if (d->package.isValid() && path.scheme() == > QStringLiteral("plasmapackage")) { > - //FIXME: this is incorrect but works around a bug in qml in > resolution of urls of qmldir files > - if (type == QQmlAbstractUrlInterceptor::QmldirFile) { > - return QUrl(d->package.filePath(0, path.path())); > - } else { > - return QUrl::fromLocalFile(d->package.filePath(0, path.path())); > - } > - } > - > - //TODO: security: permission for remote urls > - if (!path.isLocalFile()) { > - return path; > - } > - > - //if is just a normal string, no qml file was asked, allow it > - if (type == QQmlAbstractUrlInterceptor::UrlString) { > - return path; > - } > - > - //asked a file inside a package: let's rewrite the url! > - if (path.path().startsWith(package.path())) { > - //qDebug() << "Found URL in package" << path; > - > - //tries to isolate the relative path asked relative to the > contentsPrefixPath: like ui/foo.qml > - QString relativePath; > - foreach (const QString &prefix, package.contentsPrefixPaths()) { > - QString root = package.path() + prefix; > - if (path.path().startsWith(root)) { > - //obtain a string in the form ui/foo/bar/baz.qml > - relativePath = path.path().mid(root.length()); > - break; > - } > - } > - > - //should never happen > - Q_ASSERT(!relativePath.isEmpty()); > - > - const int firstSlash = relativePath.indexOf(QLatin1Char('/')) + 1; > - const QString filename = firstSlash > 0 ? > relativePath.mid(firstSlash) : relativePath; > - const QUrl ret = > QUrl::fromLocalFile(package.filePath(prefixForType(type, filename), > filename)); > - > - //qDebug() << "Returning" << ret; > - > - if (ret.path().isEmpty()) { > - return path; > - } > - return ret; > - > - //forbid to load random absolute paths > + if (path.toString().contains(match)) { > + QString rewritten = path.toString().replace(match, > QStringLiteral("code/\\1.js")); Only call `toString()` once, also put in a variable. Also we can use the information from the first match to do the replace so we don't have to execute the regex twice, if it's a hot path. REPOSITORY R242 Plasma Framework (Library) REVISION DETAIL https://phabricator.kde.org/D9124 To: mart, #plasma Cc: apol, plasma-devel, #frameworks, ZrenBot, progwolff, lesliezhai, ali-mohamed, jensreuterberg, abetts, sebas, mart