Skip to content

Commit

Permalink
Fix the bug caused by 1.1.1 (ill-formed URLs)
Browse files Browse the repository at this point in the history
  • Loading branch information
maddouri committed Apr 18, 2016
1 parent 0d10322 commit ebc67dd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
4 changes: 2 additions & 2 deletions resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<idea-plugin version="2">
<id>io.github.maddouri.intellij.OnlineSearch</id>
<name>OnlineSearch</name>
<version>1.1.1</version>
<version>1.1.2</version>
<vendor url="https://github.com/maddouri/IntelliJ-OnlineSearch"/>

<description><![CDATA[
Expand All @@ -22,7 +22,7 @@

<change-notes><![CDATA[
<ul>
<li>Fix Issue <a href="https://github.com/maddouri/IntelliJ-OnlineSearch/issues/1">#1 (if url has #)</a>: it is now possible to use a custom "query string placeholder" for each search engine</li>
<li>Fix the bug caused by 1.1.1 (ill-formed URLs were generated for pre-1.1.1 users)</li>
</ul>
]]>
</change-notes>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ebc67dd

Please sign in to comment.