summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMuhammet Kara <muhammet.kara@pardus.org.tr>2018-10-08 14:43:12 +0300
committerMuhammet Kara <muhammet.kara@pardus.org.tr>2018-10-09 19:41:09 +0200
commite59ea346d31d416e61b963648e78c5c7f13d8551 (patch)
treec3f204baa870cd7a5410f5029928d7698d87b91c
parent1b8886ad7744fc48e09bb7379d8ad8e75bb3084d (diff)
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 <muhammet.kara@pardus.org.tr>
-rw-r--r--cui/inc/strings.hrc1
-rw-r--r--cui/source/options/personalization.cxx21
2 files changed, 22 insertions, 0 deletions
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";