rospy: #1822 disallow '/' in node name and updated legal name rule for future use

This commit is contained in:
Ken Conley 2009-10-02 00:36:57 +00:00
parent 9086093533
commit 18db572e86
3 changed files with 23 additions and 2 deletions

View File

@ -201,7 +201,7 @@ def is_valid_local_name(name):
# TODO: redo this, this is very old # TODO: redo this, this is very old
import re import re
NAME_LEGAL_CHARS_P = re.compile('^[A-Za-z][\w_\-\+\/]*$') #ascii char followed by (alphanumeric, -, _, +, /) NAME_LEGAL_CHARS_P = re.compile('^[A-Za-z][\w_\/]*$') #ascii char followed by (alphanumeric, _, /)
def is_legal_resource_name(name): def is_legal_resource_name(name):
if not name: #None or empty if not name: #None or empty
return False return False

View File

@ -126,7 +126,7 @@ def init_node(name, argv=sys.argv, anonymous=False, log_level=INFO, disable_rost
only allowed if the arguments are identical as the side-effects of only allowed if the arguments are identical as the side-effects of
this method are not reversible. this method are not reversible.
@param name: Node's name @param name: Node's name. This parameter cannot contain namespaces (i.e. '/')
@type name: string @type name: string
@param argv: Command line arguments to this program. ROS reads @param argv: Command line arguments to this program. ROS reads
@ -158,7 +158,11 @@ def init_node(name, argv=sys.argv, anonymous=False, log_level=INFO, disable_rost
@type disable_rostime: bool @type disable_rostime: bool
@raise ROSInitException: if initialization/registration fails @raise ROSInitException: if initialization/registration fails
@raise ValueError: if parameters are invalid (e.g. name contains a namespace or is otherwise illegal)
""" """
# TODO use roslib.names.is_legal_name to really validate
if rospy.names.SEP in name:
raise ValueError("name cannot contain a namespace")
global _init_node_args global _init_node_args

View File

@ -49,6 +49,23 @@ import rospy
class TestRospyClient(unittest.TestCase): class TestRospyClient(unittest.TestCase):
def test_init_node(self):
failed = True
try:
# #1822
rospy.init_node('ns/node')
except ValueError:
failed = False
self.failIf(failed, "init_node allowed '/' in name")
def test_spin(self):
failed = True
try:
rospy.spin()
except rospy.ROSInitException:
failed = False
self.failIf(failed, "spin() should failed if not initialized")
def test_myargv(self): def test_myargv(self):
orig_argv = sys.argv orig_argv = sys.argv
try: try: