Skip to content

Commit 339da45

Browse files
authored
Fixes #40 - encoding issue when URL contains non-ASCII characters. (#42)
1 parent 3843271 commit 339da45

File tree

6 files changed

+48
-16
lines changed

6 files changed

+48
-16
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,8 @@ All Notable changes to `Open in Git host` will be documented in this file
5151

5252
## 2.0.0 - 2017-09-17
5353

54-
- Rebuilt the entire plugin! Note that you have to configure the plugin again!
54+
- Rebuilt the entire plugin! Note that you have to configure the plugin again!
55+
56+
## 2.0.1 - 2017-09-30
57+
58+
- Fixed encoding issue when URL contains non-ASCII characters. #40

resources/META-INF/plugin.xml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<idea-plugin url="https://github.com/ben-gibson/jetbrains-open-in-git-host">
22
<id>uk.co.ben-gibson.remote.repository.mapper</id>
33
<name>Open in Git host</name>
4-
<version>2.0.0</version>
4+
<version>2.0.1</version>
55
<vendor url="https://github.com/ben-gibson/jetbrains-open-in-git-host">Ben Gibson</vendor>
66
<description><![CDATA[
77
Determines the remote URL of a git commit or file and runs it through enabled extensions. Extensions allow the URL to be
@@ -25,13 +25,7 @@
2525
<change-notes><![CDATA[
2626
<ul>
2727
<li>
28-
Rebuilt code base for a cleaner more modular plugin that will scale better in future updates!
29-
</li>
30-
<li>
31-
Note: Plugin settings will need to be reconfigured!
32-
</li>
33-
<li>
34-
Note: No support for GitBlit - to be re-added in upcoming update.
28+
Fixed encoding issue when URL contains non-ASCII characters. <a href="https://github.com/ben-gibson/jetbrains-open-in-git-host/issues/40">#40</a>
3529
</li>
3630
</ul>
3731
]]>

src/uk/co/ben_gibson/open/in/git/host/Extension/OpenInBrowserExtension.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ public OpenInBrowserExtension(BrowserLauncher browserLauncher)
1818

1919
public void run(URL remoteUrl) throws ExtensionException
2020
{
21-
this.browserLauncher.open(remoteUrl.toString());
21+
try {
22+
this.browserLauncher.open(remoteUrl.toURI().toASCIIString());
23+
} catch (Exception e) {
24+
throw new ExtensionException(e.getMessage());
25+
}
26+
2227
}
2328

2429
public String displayName()

src/uk/co/ben_gibson/open/in/git/host/UI/Target/SelectInTarget.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
import git4idea.repo.GitRepository;
1414
import org.jetbrains.annotations.NotNull;
1515
import uk.co.ben_gibson.open.in.git.host.Container;
16-
import uk.co.ben_gibson.open.in.git.host.Git.Commit;
1716
import uk.co.ben_gibson.open.in.git.host.Logger.Logger;
18-
import uk.co.ben_gibson.open.in.git.host.RemoteUrlFactory.Description.RemoteCommitDescription;
1917
import uk.co.ben_gibson.open.in.git.host.UI.Exception.RepositoryNotFoundException;
2018
import uk.co.ben_gibson.open.in.git.host.Exception.OpenInGitHostException;
2119
import uk.co.ben_gibson.open.in.git.host.Git.Branch;
Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,47 @@
11
package uk.co.ben_gibson.open.in.git.host.test.Extension;
22

33
import com.intellij.ide.browsers.BrowserLauncher;
4+
import com.tngtech.java.junit.dataprovider.DataProvider;
5+
import com.tngtech.java.junit.dataprovider.DataProviderRunner;
6+
import com.tngtech.java.junit.dataprovider.UseDataProvider;
47
import junit.framework.TestCase;
8+
import org.junit.Test;
9+
import org.junit.runner.RunWith;
510
import uk.co.ben_gibson.open.in.git.host.Extension.Exception.ExtensionException;
611
import uk.co.ben_gibson.open.in.git.host.Extension.Extension;
712
import uk.co.ben_gibson.open.in.git.host.Extension.OpenInBrowserExtension;
813
import static org.mockito.Mockito.*;
914
import java.net.MalformedURLException;
1015
import java.net.URL;
1116

17+
@RunWith(DataProviderRunner.class)
1218
public class OpenInBrowserExtensionTest extends TestCase
1319
{
14-
public void testOpensInBrowser() throws MalformedURLException, ExtensionException
20+
@Test
21+
@UseDataProvider("urlProvider")
22+
public void testOpensInBrowser(URL url, String expected) throws MalformedURLException, ExtensionException
1523
{
16-
URL url = new URL("https://example.com");
17-
1824
BrowserLauncher browserLauncher = mock(BrowserLauncher.class);
1925

2026
Extension extension = new OpenInBrowserExtension(browserLauncher);
2127

2228
extension.run(url);
2329

24-
verify(browserLauncher, times(1)).open(url.toString());
30+
verify(browserLauncher, times(1)).open(expected);
31+
}
32+
33+
@DataProvider
34+
public static Object[][] urlProvider() throws MalformedURLException
35+
{
36+
return new Object[][] {
37+
{
38+
new URL("https://example.com"),
39+
"https://example.com"
40+
},
41+
{
42+
new URL("https://github.com/foo%20bar/baz/blob/master/需求0920-2017/0928.sql#L15"),
43+
"https://github.com/foo%20bar/baz/blob/master/%E9%9C%80%E6%B1%820920-2017/0928.sql#L15"
44+
},
45+
};
2546
}
2647
}

tests/unit/uk/co/ben_gibson/open/in/git/host/test/RemoteUrlFactory/GitHubRemoteUrlFactoryTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,16 @@ public static Object[][] fileProvider() throws MalformedURLException, RemoteExce
9595
"https://github.com/foo%20bar/baz/blob/master/resources/Bar%20Baz.java",
9696
true
9797
},
98+
{
99+
new RemoteFileDescription(
100+
RemoteUrlFactoryTest.mockRemote("https://github.com/foo bar/baz"),
101+
Branch.master(),
102+
RemoteUrlFactoryTest.mockFile("需求0920-2017/0928.sql", "0928.sql"),
103+
15
104+
),
105+
"https://github.com/foo%20bar/baz/blob/master/需求0920-2017/0928.sql#L15",
106+
true
107+
},
98108
};
99109
}
100110

0 commit comments

Comments
 (0)