Merge pull request #586 from hunbernd/fix/external-emoticons

Fixed loading of external emoticons
This commit is contained in:
defnax 2016-11-30 08:12:38 +01:00 committed by GitHub
commit d616df3b28

View File

@ -102,11 +102,14 @@ QVariant RSTextBrowser::loadResource(int type, const QUrl &name)
// case 2: always trust the image if it comes from local Config or Data directories.
if(name.scheme().compare("file",Qt::CaseInsensitive)==0 && type == QTextDocument::ImageResource) {
if (name.path().startsWith(QDir(QString::fromUtf8(RsAccounts::ConfigDirectory().c_str())).absolutePath().prepend("/"),Qt::CaseInsensitive)
|| name.path().startsWith(QDir(QString::fromUtf8(RsAccounts::DataDirectory().c_str())).absolutePath().prepend("/"),Qt::CaseInsensitive))
return QTextBrowser::loadResource(type, name);
}
if(type == QTextDocument::ImageResource) {
QFileInfo fi = QFileInfo(name.path());
if(fi.exists() && fi.isFile()) {
QString cpath = fi.canonicalFilePath();
if (cpath.startsWith(QDir(QString::fromUtf8(RsAccounts::ConfigDirectory().c_str())).canonicalPath(),Qt::CaseInsensitive)
|| cpath.startsWith(QDir(QString::fromUtf8(RsAccounts::DataDirectory().c_str())).canonicalPath(),Qt::CaseInsensitive))
return QTextBrowser::loadResource(type, name);
}}
// case 3: only display if the user allows it. Data resources can be bad (svg bombs) but we filter them out globally at the network layer.
// It would be good to add here a home-made resource loader that only loads images and not svg crap, just in case.