Skip to content

Commit

Permalink
Allow remote SVG files with text/plain MIME type, instead of only
Browse files Browse the repository at this point in the history
valid image/svg+xml mime types

This allows users to link to SVG files hosted on github, where
the raw content is served up as plain text.

(cherry-picked from d3aae3f)
  • Loading branch information
nyalldawson committed Apr 2, 2018
1 parent 2f695b9 commit 7af4997
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/core/symbology/qgssvgcache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,10 +461,13 @@ QByteArray QgsSvgCache::getImageData( const QString &path ) const
return mMissingSvg;
}

// we accept both real SVG mime types AND plain text types - because some sites
// (notably github) serve up svgs as raw text
QString contentType = reply->header( QNetworkRequest::ContentTypeHeader ).toString();
QgsDebugMsg( "contentType: " + contentType );
if ( !contentType.startsWith( QLatin1String( "image/svg+xml" ), Qt::CaseInsensitive ) )
if ( !contentType.startsWith( QLatin1String( "image/svg+xml" ), Qt::CaseInsensitive )
&& !contentType.startsWith( QLatin1String( "text/plain" ), Qt::CaseInsensitive ) )
{
QgsMessageLog::logMessage( tr( "Unexpected MIME type %1 received for %2" ).arg( contentType, path ), tr( "SVG" ) );
reply->deleteLater();
return mMissingSvg;
}
Expand Down

0 comments on commit 7af4997

Please sign in to comment.