Commit 17bedaff authored by Mygod's avatar Mygod

Fix #1064

parent 49fbfcc2
......@@ -80,7 +80,7 @@ class Acl {
}
case _ =>
}
this.subnets ++= (if (bypass) bypassSubnets else proxySubnets)
this.subnets ++= (if (bypass) proxySubnets else bypassSubnets)
this
}
final def fromId(id: String): Acl = fromSource(Source.fromFile(Acl.getPath(id)))
......@@ -90,8 +90,8 @@ class Acl {
result.append(if (bypass) "[bypass_all]\n" else "[proxy_all]\n")
var bypassList = bypassHostnames.toStream
var proxyList = proxyHostnames.toStream
if (bypass) bypassList = subnets.toStream.map(_.toString) #::: bypassList
else proxyList = subnets.toStream.map(_.toString) #::: proxyList
if (bypass) proxyList = subnets.toStream.map(_.toString) #::: bypassList
else bypassList = subnets.toStream.map(_.toString) #::: proxyList
if (bypassList.nonEmpty) {
result.append("[bypass_list]\n")
result.append(bypassList.mkString("\n"))
......
......@@ -95,8 +95,13 @@ class CustomRulesFragment extends ToolbarFragment with Toolbar.OnMenuItemClickLi
}): DialogInterface.OnClickListener)
.setPositiveButton(android.R.string.ok, ((_, _) =>
adapter.addFromTemplate(templateSelector.getSelectedItemPosition, editText.getText) match {
case -1 => adapter.remove(item)
case index => list.post(() => list.scrollToPosition(index))
case -1 =>
case index =>
val item = this.item
list.post(() => {
list.scrollToPosition(index)
adapter.remove(item)
})
})
: DialogInterface.OnClickListener)
.create().show()
......@@ -203,13 +208,15 @@ class CustomRulesFragment extends ToolbarFragment with Toolbar.OnMenuItemClickLi
def getSectionTitle(i: Int): String = {
val j = i - acl.subnets.size
(if (j < 0) acl.subnets(i).address.toString.charAt(0).toString else {
try (if (j < 0) acl.subnets(i).address.getHostAddress.substring(0, 1) else {
val hostname = acl.proxyHostnames(i)
PATTERN_DOMAIN.findFirstMatchIn(hostname) match {
case Some(m) => m.matched.replaceAll("\\\\.", ".") // don't convert IDN yet
case None => hostname
}
}).substring(0, 1)
}).substring(0, 1) catch {
case _: IndexOutOfBoundsException => " "
}
}
}
......
......@@ -18,7 +18,7 @@ class Subnet(val address: InetAddress, val prefixSize: Int) extends Comparable[S
override def toString: String = if (address match {
case _: Inet4Address => prefixSize == 32
case _: Inet6Address => prefixSize == 128
}) address.toString else address.toString + '/' + prefixSize
}) address.getHostAddress else address.getHostAddress + '/' + prefixSize
override def compareTo(that: Subnet): Int = {
val addrThis = address.getAddress
......
......@@ -39,7 +39,10 @@ class SortedList[A] private(treeRef: ObjectRef[RB.Tree[A, Null]], from: Option[A
}
// AbstractSeq
def apply(i: Int): A = RB.nth(treeRef.elem, i).key // Should i out of range result in NullReferenceException?
def apply(i: Int): A = try RB.nth(treeRef.elem, i).key catch {
// out of bounds will result in accessing null nodes
case e: NullPointerException => throw new IndexOutOfBoundsException().initCause(e)
}
def length: Int = size
// Buffer
......
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