diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index f4768ee..041cf74 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -1,7 +1,7 @@ io.github.maddouri.intellij.OnlineSearch OnlineSearch - 1.1.1 + 1.1.2 -
  • Fix Issue #1 (if url has #): it is now possible to use a custom "query string placeholder" for each search engine
  • +
  • Fix the bug caused by 1.1.1 (ill-formed URLs were generated for pre-1.1.1 users)
  • ]]> diff --git a/src/io/github/maddouri/intellij/OnlineSearch/action/LaunchSearchAction.java b/src/io/github/maddouri/intellij/OnlineSearch/action/LaunchSearchAction.java index 3217bcf..ed8a1bb 100644 --- a/src/io/github/maddouri/intellij/OnlineSearch/action/LaunchSearchAction.java +++ b/src/io/github/maddouri/intellij/OnlineSearch/action/LaunchSearchAction.java @@ -87,9 +87,7 @@ private void launchSearch(final String query) { } try { - final String encodedQuery = URLEncoder.encode(query, "UTF-8"); - final String uriString = searchEngine.url.replace(searchEngine.queryPlaceholder, - encodedQuery); + final String uriString = searchEngine.generateSearchUri(query); BrowserLauncher.getInstance().open(uriString); diff --git a/src/io/github/maddouri/intellij/OnlineSearch/state/PluginSettings.java b/src/io/github/maddouri/intellij/OnlineSearch/state/PluginSettings.java index 8517efd..ea00f7f 100644 --- a/src/io/github/maddouri/intellij/OnlineSearch/state/PluginSettings.java +++ b/src/io/github/maddouri/intellij/OnlineSearch/state/PluginSettings.java @@ -8,6 +8,8 @@ import org.jetbrains.annotations.Nullable; import java.io.Serializable; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; import java.util.ArrayList; /** The plugin's settings. (mainly the list of search engines) @@ -48,6 +50,16 @@ public SearchEngine(String name, String url, String queryPlaceholder) { this.url = url; this.queryPlaceholder = queryPlaceholder; } + + public String generateSearchUri(final String query) throws UnsupportedEncodingException { + final String encodedQuery = URLEncoder.encode(query, "UTF-8"); + + if (queryPlaceholder == null || queryPlaceholder.equals("")) { // fix for the 1.1.1 bug causing a ill-formed URI to be generated + return url.replace(DEFAULT_QUERY_PLACEHOLDER, encodedQuery); + } else { + return url.replace(queryPlaceholder, encodedQuery); + } + } } @com.intellij.util.xmlb.annotations.Transient // exclude from state