Skip to content

Commit

Permalink
Also check for and fail when bundle commands have non-ASCII unicode c…
Browse files Browse the repository at this point in the history
…haracters (#1104)
  • Loading branch information
Kerem Goksel authored Mar 19, 2019
1 parent c782975 commit a568aaa
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
11 changes: 7 additions & 4 deletions codalab/model/bundle_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -919,10 +919,13 @@ def save_bundle(self, bundle):
# (Clients should check for this case ahead of time if they want to
# silently skip over creating bundles that already exist.)
with self.engine.begin() as connection:
result = connection.execute(cl_bundle.insert().values(bundle_value))
self.do_multirow_insert(connection, cl_bundle_dependency, dependency_values)
self.do_multirow_insert(connection, cl_bundle_metadata, metadata_values)
bundle.id = result.lastrowid
try:
result = connection.execute(cl_bundle.insert().values(bundle_value))
self.do_multirow_insert(connection, cl_bundle_dependency, dependency_values)
self.do_multirow_insert(connection, cl_bundle_metadata, metadata_values)
bundle.id = result.lastrowid
except UnicodeError:
raise UsageError("Invalid character detected; use ascii characters only.")

def update_bundle(self, bundle, update, connection=None):
"""
Expand Down
2 changes: 1 addition & 1 deletion codalab/rest/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ class BundleSchema(Schema):
bundle_type = fields.String(
validate=validate.OneOf({bsc.BUNDLE_TYPE for bsc in BUNDLE_SUBCLASSES})
)
command = fields.String(allow_none=True)
command = fields.String(allow_none=True, validate=validate_ascii)
data_hash = fields.String()
state = fields.String()
owner = fields.Relationship(include_resource_linkage=True, type_='users', attribute='owner_id')
Expand Down
3 changes: 2 additions & 1 deletion test-cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1651,9 +1651,10 @@ def test(ctx):
check_equals('_', get_info(uuid, 'name')) # Currently ignores unicode chars for name
check_equals('你好世界😊', run_command([cl, 'cat', uuid]))

# Unicode in bundle description and tags
# Unicode in bundle description, tags and command
run_command([cl, 'upload', test_path('a.txt'), '--description', '你好'], 1)
run_command([cl, 'upload', test_path('a.txt'), '--tags', 'test', '😁'], 1)
run_command([cl, 'run', 'echo "fáncy ünicode"'], 1)

# Unicode in edits --> interactive mode not tested, but `cl edit` properly discards
# edits that introduce unicode.
Expand Down

0 comments on commit a568aaa

Please sign in to comment.