Skip to content

Commit 9d50d9e

Browse files
fixes #23 - handle hexadecimal encoded files such as %2B (+) and %40 (@) in connection name
1 parent da5001b commit 9d50d9e

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

sqldev/src/main/java/org/utplsql/sqldev/model/URLTools.xtend

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,24 @@ import java.net.URL
1818
import java.util.regex.Pattern
1919

2020
class URLTools {
21+
def replaceHexChars(String input) {
22+
var String output = input;
23+
val p = Pattern.compile("%([0-9A-F]{2})")
24+
val m = p.matcher(input)
25+
while (m.find) {
26+
val what = m.group(0);
27+
val decimal = Integer.parseInt(m.group(1), 16)
28+
val with = String.valueOf(decimal as char)
29+
output = output.replace(what, with)
30+
}
31+
return output
32+
}
33+
2134
def getConnectionName(URL url) {
2235
val p = Pattern.compile("(sqldev.nav:)([^/]+)(//)?")
2336
val m = p.matcher(url.toString)
2437
if (m.find) {
25-
return m.group(2).replace("IdeConnections%2523", "IdeConnections%23").replace("%2B", "+")
38+
return m.group(2).replace("IdeConnections%2523", "IdeConnections%23").replaceHexChars
2639
} else {
2740
return ""
2841
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package org.utplsql.sqldev.tests
2+
3+
import org.junit.Assert
4+
import org.junit.Test
5+
import org.utplsql.sqldev.model.URLTools
6+
7+
class UrlToolsTest {
8+
private val extension URLTools urlTools = new URLTools
9+
10+
@Test
11+
def void testReplacePlusSign() {
12+
Assert.assertEquals("+", "%2B".replaceHexChars)
13+
Assert.assertEquals("++", "%2B%2B".replaceHexChars)
14+
Assert.assertEquals("abc+%xyz", "abc%2B%xyz".replaceHexChars)
15+
}
16+
17+
@Test
18+
def void testReplaceAtSign() {
19+
Assert.assertEquals("@", "%40".replaceHexChars)
20+
Assert.assertEquals("@@", "%40%40".replaceHexChars)
21+
Assert.assertEquals("abc@%xyz", "abc%40%xyz".replaceHexChars)
22+
}
23+
24+
@Test
25+
def void testReplaceAtAndPlusSign() {
26+
Assert.assertEquals("@+", "%40%2B".replaceHexChars)
27+
Assert.assertEquals("@+@+", "%40%2B%40%2B".replaceHexChars)
28+
Assert.assertEquals("abc@+%xyz", "abc%40%2B%xyz".replaceHexChars)
29+
}
30+
31+
}

0 commit comments

Comments
 (0)