Skip to content

Commit b9c920c

Browse files
committed
Fix slash issue in HTTP URI
See #85
1 parent 80bf6e1 commit b9c920c

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/main/kotlin/org/bsplines/ltexls/languagetool/LanguageToolHttpInterface.kt

+7-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ class LanguageToolHttpInterface(
4242
var exception: Exception? = null
4343
this.uri =
4444
try {
45-
URI(uriString + "/v2/check").toURL().toURI()
45+
if (uriString.last().toString() == "/") {
46+
URI(uriString + "v2/check").toURL().toURI()
47+
} else {
48+
URI(uriString + "/v2/check").toURL().toURI()
49+
}
4650
} catch (e: MalformedURLException) {
4751
exception = e
4852
null
@@ -56,6 +60,8 @@ class LanguageToolHttpInterface(
5660
}
5761
}
5862

63+
fun getURIString(): String = this.uri.toString()
64+
5965
override fun isInitialized(): Boolean = (this.uri != null)
6066

6167
override fun checkInternal(

src/test/kotlin/org/bsplines/ltexls/languagetool/LanguageToolHttpInterfaceTest.kt

+9
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,16 @@ class LanguageToolHttpInterfaceTest {
4545

4646
@Test
4747
fun testConstructor() {
48+
assertTrue(LanguageToolHttpInterface("http://localhost:8081", "en-US", "").isInitialized())
4849
assertTrue(LanguageToolHttpInterface("http://localhost:8081/", "en-US", "").isInitialized())
50+
assertTrue(
51+
LanguageToolHttpInterface("http://localhost:8081/", "en-US", "").getURIString() ==
52+
"http://localhost:8081/v2/check",
53+
)
54+
assertTrue(
55+
LanguageToolHttpInterface("http://localhost:8081", "en-US", "").getURIString() ==
56+
"http://localhost:8081/v2/check",
57+
)
4958
assertFalse(LanguageToolHttpInterface("http://localhost:80:81/", "en-US", "").isInitialized())
5059
}
5160

0 commit comments

Comments
 (0)