cui/inc/strings.hrc | 1 + cui/source/options/personalization.cxx | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+)
New commits: commit e59ea346d31d416e61b963648e78c5c7f13d8551 Author: Muhammet Kara <[email protected]> AuthorDate: Mon Oct 8 14:43:12 2018 +0300 Commit: Muhammet Kara <[email protected]> CommitDate: Tue Oct 9 19:41:09 2018 +0200 tdf#101629: Handle invalid urls and search strings for Personas Change-Id: I9666aa9f323e53ef394121acdef146866d2cc696 Reviewed-on: https://gerrit.libreoffice.org/61529 Tested-by: Jenkins Reviewed-by: Muhammet Kara <[email protected]> diff --git a/cui/inc/strings.hrc b/cui/inc/strings.hrc index 06347dea6bcc..71ff45488568 100644 --- a/cui/inc/strings.hrc +++ b/cui/inc/strings.hrc @@ -371,6 +371,7 @@ #define RID_SVXSTR_SEARCHERROR NC_("RID_SVXSTR_SEARCHERROR", "Cannot open %1, please try again later.") #define RID_SVXSTR_NORESULTS NC_("RID_SVXSTR_NORESULTS", "No results found.") #define RID_SVXSTR_APPLYPERSONA NC_("RID_SVXSTR_APPLYPERSONA", "Applying Theme...") +#define RID_SVXSTR_INVALIDPERSONAURL NC_("RID_SVXSTR_INVALIDPERSONAURL", "Please enter a valid theme address or a search term.") #define RID_SVXSTR_TABLE_PRESET_NONE NC_("RID_SVXSTR_TABLE_PRESET_NONE", "Set No Borders") #define RID_SVXSTR_TABLE_PRESET_ONLYOUTER NC_("RID_SVXSTR_TABLE_PRESET_ONLYOUTER", "Set Outer Border Only") diff --git a/cui/source/options/personalization.cxx b/cui/source/options/personalization.cxx index 0c88f9adf325..ae314e1019c8 100644 --- a/cui/source/options/personalization.cxx +++ b/cui/source/options/personalization.cxx @@ -284,14 +284,35 @@ IMPL_LINK( SelectPersonaDialog, SearchPersonas, Button*, pButton, void ) if( searchTerm.isEmpty( ) ) return; + // Direct url of a persona given if ( searchTerm.startsWith( "https://addons.mozilla.org/" ) ) { OUString sSlug = searchTerm.getToken( 6, '/' ); + // Check if we got the slug + if ( sSlug.isEmpty() ) + { + SolarMutexGuard aGuard; + OUString sError = CuiResId( RID_SVXSTR_INVALIDPERSONAURL ); + std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(nullptr, + VclMessageType::Error, VclButtonsType::Ok, + sError)); + xBox->run(); + return; + } + + // Remove invalid characters + searchTerm = searchTerm.replaceAll("?", ""); + m_pSearchThread = new SearchAndParseThread( this, sSlug, true ); } + // Search term given else { + // Remove invalid characters + searchTerm = searchTerm.replaceAll("/", ""); + searchTerm = searchTerm.replaceAll("?", ""); + // 15 results so that invalid and duplicate search results whose names, textcolors etc. are null can be skipped OUString rSearchURL = "https://addons.mozilla.org/api/v3/addons/search/?q=" + searchTerm + "&type=persona&page_size=15"; _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
