check validity of path elements (actor names), see #1567

This commit is contained in:
Roland 2011-12-29 17:32:35 +01:00
parent c4f3a93268
commit df02ca73fb
3 changed files with 18 additions and 2 deletions

View file

@ -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)
}
}
}

View file

@ -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)

View file

@ -15,6 +15,8 @@ object ActorPath {
}
rec(s.length, Nil)
}
val ElementRegex = """[-\w:@&=+,.!~*'_;][-\w:@&=+,.!~*'$_;]*""".r
}
/**