From e89402dda0c2b3cf7bf604ccfce63b224f9ab368 Mon Sep 17 00:00:00 2001 From: Konrad Malawski Date: Wed, 17 Jun 2015 16:37:21 +0200 Subject: [PATCH] =act #17690 add additional validation for name param in RootActorPath --- .../src/test/scala/akka/actor/ActorPathSpec.scala | 10 ++++++++++ akka-actor/src/main/scala/akka/actor/ActorPath.scala | 4 ++++ akka-docs/rst/project/migration-guide-2.3.x-2.4.x.rst | 10 ++++++++++ 3 files changed, 24 insertions(+) diff --git a/akka-actor-tests/src/test/scala/akka/actor/ActorPathSpec.scala b/akka-actor-tests/src/test/scala/akka/actor/ActorPathSpec.scala index 5559ad7a79..ae2fc3e66b 100644 --- a/akka-actor-tests/src/test/scala/akka/actor/ActorPathSpec.scala +++ b/akka-actor-tests/src/test/scala/akka/actor/ActorPathSpec.scala @@ -76,5 +76,15 @@ class ActorPathSpec extends WordSpec with Matchers { (rootA / "user").toStringWithAddress(b) should ===("akka.tcp://mysys@aaa:2552/user") (rootA / "user" / "foo").toStringWithAddress(b) should ===("akka.tcp://mysys@aaa:2552/user/foo") } + + "not allow path separators in RootActorPath's name" in { + intercept[IllegalArgumentException] { + RootActorPath(Address("akka.tcp", "mysys"), "/user/boom/*") // illegally pass in a path where name is expected + }.getMessage should include("is a path separator") + + // sanity check that creating such path still works + ActorPath.fromString("akka://mysys/user/boom/*") + } + } } diff --git a/akka-actor/src/main/scala/akka/actor/ActorPath.scala b/akka-actor/src/main/scala/akka/actor/ActorPath.scala index 03a0a761ab..16a825d9b6 100644 --- a/akka-actor/src/main/scala/akka/actor/ActorPath.scala +++ b/akka-actor/src/main/scala/akka/actor/ActorPath.scala @@ -254,6 +254,10 @@ sealed trait ActorPath extends Comparable[ActorPath] with Serializable { */ @SerialVersionUID(1L) final case class RootActorPath(address: Address, name: String = "/") extends ActorPath { + require(name.length == 1 || name.indexOf('/', 1) == -1, + "/ may only exist at the beginning of the root actors name, " + + "it is a path separator and is not legal in ActorPath names: [%s]" format name) + require(name.indexOf('#') == -1, "# is a fragment separator and is not legal in ActorPath names: [%s]" format name) override def parent: ActorPath = this diff --git a/akka-docs/rst/project/migration-guide-2.3.x-2.4.x.rst b/akka-docs/rst/project/migration-guide-2.3.x-2.4.x.rst index 1d150d9703..646a42dadd 100644 --- a/akka-docs/rst/project/migration-guide-2.3.x-2.4.x.rst +++ b/akka-docs/rst/project/migration-guide-2.3.x-2.4.x.rst @@ -30,6 +30,16 @@ in practice. No changes were needed to the Akka source code for this update. Use depend on 3.8.0.Final that break with 3.10.3.Final should be able to manually downgrade the dependency to 3.8.0.Final and Akka will still work with that version. +Added parameter validation to RootActorPath +=========================================== +Previously ``akka.actor.RootActorPath`` allowed passing in arbitrary strings into its name parameter, +which is meant to be the *name* of the root Actor. Subsequently, if constructed with an invalid name +such as a full path for example (``/user/Full/Path``) some features using this path may transparently fail - +such as using ``actorSelection`` on such invalid path. + +In Akka 2.4.x the ``RootActorPath`` validates the input and may throw an ``IllegalArgumentException`` if +the passed in name string is illegal (contains ``/`` elsewhere than in the begining of the string or contains ``#``). + Advanced Notice: TypedActors will go away =========================================