Skip to content

Commit

Permalink
Added checks for valid resource slugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Seraphim Mellos committed Aug 20, 2010
1 parent 2229e0d commit 9c724b2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions txclib/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ def cmd_set_source_file(argv, path_to_tx=None):
return
for opt, arg in opts:
if opt in ("-r", "--resource"):
if not valid_slug(arg):
raise Exception("Valid characters for resource slugs are [-_\w]")
resource = arg
elif opt in ("-l", "--lang"):
lang = arg
Expand Down
10 changes: 10 additions & 0 deletions txclib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,13 @@ def get_opener(host, username, passwd):
return opener


def valid_slug(slug):
"""
Check if a slug contains only valid characters.
Valid chars include [-_\w]
"""
if re.match("^[A-Za-z0-9_-]*$", slug):
return True
return False

0 comments on commit 9c724b2

Please sign in to comment.