File tree Expand file tree Collapse file tree 2 files changed +45
-1
lines changed
main/java/org/utplsql/sqldev/model
test/java/org/utplsql/sqldev/tests Expand file tree Collapse file tree 2 files changed +45
-1
lines changed Original file line number Diff line number Diff line change @@ -18,11 +18,24 @@ import java.net.URL
18
18
import java.util.regex.Pattern
19
19
20
20
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
+
21
34
def getConnectionName (URL url ) {
22
35
val p = Pattern . compile(" (sqldev.nav:)([^/]+)(//)?" )
23
36
val m = p. matcher(url. toString)
24
37
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
26
39
} else {
27
40
return " "
28
41
}
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments