check validity of path elements (actor names), see #1567
This commit is contained in:
parent
c4f3a93268
commit
df02ca73fb
3 changed files with 18 additions and 2 deletions
|
|
@ -54,5 +54,14 @@ class LocalActorRefProviderSpec extends AkkaSpec {
|
|||
}
|
||||
}
|
||||
|
||||
"throw suitable exceptions for malformed actor names" in {
|
||||
intercept[InvalidActorNameException](system.actorOf(Props.empty, null)).getMessage.contains("null") must be(true)
|
||||
intercept[InvalidActorNameException](system.actorOf(Props.empty, "")).getMessage.contains("empty") must be(true)
|
||||
intercept[InvalidActorNameException](system.actorOf(Props.empty, "$hallo")).getMessage.contains("conform") must be(true)
|
||||
intercept[InvalidActorNameException](system.actorOf(Props.empty, "a%")).getMessage.contains("conform") must be(true)
|
||||
intercept[InvalidActorNameException](system.actorOf(Props.empty, "a?")).getMessage.contains("conform") must be(true)
|
||||
intercept[InvalidActorNameException](system.actorOf(Props.empty, "üß")).getMessage.contains("conform") must be(true)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -222,8 +222,13 @@ private[akka] class ActorCell(
|
|||
def actorOf(props: Props): ActorRef = _actorOf(props, randomName())
|
||||
|
||||
def actorOf(props: Props, name: String): ActorRef = {
|
||||
if (name == null || name == "" || name.charAt(0) == '$')
|
||||
throw new InvalidActorNameException("actor name must not be null, empty or start with $")
|
||||
import ActorPath.ElementRegex
|
||||
name match {
|
||||
case null ⇒ throw new InvalidActorNameException("actor name must not be null")
|
||||
case "" ⇒ throw new InvalidActorNameException("actor name must not be empty")
|
||||
case ElementRegex() ⇒ // this is fine
|
||||
case _ ⇒ throw new InvalidActorNameException("illegal actor name '" + name + "', must conform to " + ElementRegex)
|
||||
}
|
||||
if (childrenRefs contains name)
|
||||
throw new InvalidActorNameException("actor name " + name + " is not unique!")
|
||||
_actorOf(props, name)
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@ object ActorPath {
|
|||
}
|
||||
rec(s.length, Nil)
|
||||
}
|
||||
|
||||
val ElementRegex = """[-\w:@&=+,.!~*'_;][-\w:@&=+,.!~*'$_;]*""".r
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue