Commit 2f6f991e authored by Mygod's avatar Mygod

Fix literal IPv6 address handling in URIs

parent 90e00a38
...@@ -98,7 +98,8 @@ class Profile { ...@@ -98,7 +98,8 @@ class Profile {
.scheme("ss") .scheme("ss")
.encodedAuthority("%s@%s:%d".formatLocal(Locale.ENGLISH, .encodedAuthority("%s@%s:%d".formatLocal(Locale.ENGLISH,
Base64.encodeToString("%s:%s".formatLocal(Locale.ENGLISH, method, password).getBytes, Base64.encodeToString("%s:%s".formatLocal(Locale.ENGLISH, method, password).getBytes,
Base64.NO_PADDING | Base64.NO_WRAP | Base64.URL_SAFE), host, remotePort)) Base64.NO_PADDING | Base64.NO_WRAP | Base64.URL_SAFE),
if (host.contains(':')) '[' + host + ']' else host, remotePort))
val configuration = new PluginConfiguration(plugin) val configuration = new PluginConfiguration(plugin)
if (configuration.selected.nonEmpty) if (configuration.selected.nonEmpty)
builder.appendQueryParameter(Key.plugin, configuration.selectedOptions.toString(false)) builder.appendQueryParameter(Key.plugin, configuration.selectedOptions.toString(false))
......
...@@ -20,13 +20,15 @@ ...@@ -20,13 +20,15 @@
package com.github.shadowsocks.utils package com.github.shadowsocks.utils
import java.net.URI
import android.net.Uri import android.net.Uri
import android.util.{Base64, Log} import android.util.{Base64, Log}
import com.github.shadowsocks.database.Profile import com.github.shadowsocks.database.Profile
object Parser { object Parser {
val TAG = "ShadowParser" val TAG = "ShadowParser"
private val pattern = "(?i)ss://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]".r private val pattern = "(?i)ss://[-a-zA-Z0-9+&@#/%?=~_|!:,.;\\[\\]]*[-a-zA-Z0-9+&@#/%=~_|\\[\\]]".r
private val userInfoPattern = "^(.+?):(.*)$".r private val userInfoPattern = "^(.+?):(.*)$".r
private val legacyPattern = "^(.+?):(.*)@(.+?):(\\d+?)$".r private val legacyPattern = "^(.+?):(.*)@(.+?):(\\d+?)$".r
...@@ -54,8 +56,12 @@ object Parser { ...@@ -54,8 +56,12 @@ object Parser {
val profile = new Profile val profile = new Profile
profile.method = method profile.method = method
profile.password = password profile.password = password
profile.host = uri.getHost // bug in Android: https://code.google.com/p/android/issues/detail?id=192855
profile.remotePort = uri.getPort val javaURI = new URI(m.matched)
profile.host = javaURI.getHost
if (profile.host.headOption.contains('[') && profile.host.lastOption.contains(']'))
profile.host = profile.host.substring(1, profile.host.length - 1)
profile.remotePort = javaURI.getPort
profile.plugin = uri.getQueryParameter(Key.plugin) profile.plugin = uri.getQueryParameter(Key.plugin)
profile.name = uri.getFragment profile.name = uri.getFragment
profile profile
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment