Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce UTF8 argv on rclpy.init() #273

Merged
merged 2 commits into from
Feb 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions rclpy/src/rclpy/_rclpy.c
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,10 @@ rclpy_init(PyObject * Py_UNUSED(self), PyObject * args)
}
// Borrows a pointer, do not free arg_values[i]
arg_values[i] = PyUnicode_AsUTF8(pyarg);
if (NULL == arg_values[i]) {
have_args = false;
break;
}
}
}

Expand Down
20 changes: 19 additions & 1 deletion rclpy/test/test_init_shutdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,25 @@ def func_init():
rclpy.init(context=context)
except RuntimeError:
return False

rclpy.shutdown(context=context)
return True


def func_init_with_non_utf8_arguments():
import rclpy
context = rclpy.context.Context()
# Embed non decodable characters e.g. due to
# wrong locale settings.
# See PEP-383 for further reference.
args = ['my-node.py', 'Ragnar\udcc3\udcb6k']
try:
rclpy.init(context=context, args=args)
except UnicodeEncodeError:
return True
rclpy.shutdown(context=context)
return False


def func_init_shutdown():
import rclpy
context = rclpy.context.Context()
Expand Down Expand Up @@ -124,6 +138,10 @@ def test_init():
func_launch(func_init, 'failed to initialize rclpy')


def test_init_with_non_utf8_arguments():
func_launch(func_init_with_non_utf8_arguments, 'handled non UTF-8 arguments')


def test_init_shutdown():
func_launch(func_init_shutdown, 'failed to shutdown rclpy')

Expand Down