Skip to content

Conversation

@kotfu
Copy link
Member

@kotfu kotfu commented May 6, 2018

self.identchars is no longer used by cmd2.

self.identchars is no longer used by cmd2.
@kotfu kotfu self-assigned this May 6, 2018
@kotfu kotfu requested a review from tleonhardt as a code owner May 6, 2018 04:00
@codecov
Copy link

codecov bot commented May 6, 2018

Codecov Report

Merging #391 into master will increase coverage by 0.09%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #391      +/-   ##
==========================================
+ Coverage   89.73%   89.83%   +0.09%     
==========================================
  Files           8        8              
  Lines        2621     2646      +25     
==========================================
+ Hits         2352     2377      +25     
  Misses        269      269
Impacted Files Coverage Δ
cmd2/cmd2.py 90.97% <100%> (ø) ⬆️
cmd2/parsing.py 98.27% <100%> (+0.2%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5e6a929...a4962ab. Read the comment docs.

@tleonhardt tleonhardt requested a review from kmvanbrunt May 6, 2018 04:12
@kmvanbrunt
Copy link
Member

This change allows the following to work.

(Cmd) alias ">" help
Alias '>' created

Can you add a restriction that prevents creating aliases containing redirection characters?

Also, we need to fix alias expansion to allow a redirection character without a space.

(Cmd) alias h help
Alias 'h' created

This works: help>out.txt
This does not work: h>out.txt

@kotfu
Copy link
Member Author

kotfu commented May 6, 2018

Given alias aliasname expansion as user input:

We shouldn't allow aliasname to include redirection characters (i.e. '>' and '|').

Should we allow aliasname to include whitespace? I think no.

Should we allow aliasname to include terminator characters? I think no.

@tleonhardt
Copy link
Member

My thoughts on what we should allow in alias names are as follows:

  • Redirection chars like > and |: no
  • Whitespace: no
  • Terminator characters: no

So basically, I'd say don't allow any of that in alias names to keep things as simple as possible.

tleonhardt
tleonhardt previously approved these changes May 7, 2018
Copy link
Member

@tleonhardt tleonhardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider my comments, but looks good

cmd2/cmd2.py Outdated
self.perror("Alias names can only contain the following characters: {}".format(self.identchars),
traceback_war=False)
return
# Validate the alias to ensure it doesn't include wierd characters
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird not wierd

second_group_items = [re.escape(x) for x in second_group_items]
# add the whitespace and end of string, not escaped because they
# are not literals
second_group_items.extend([r'\s', r'\Z'])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the same as invalid_items just with one more item appended? If so recommend making a copy of the former to minimize duplicated code

Copy link
Member Author

@kotfu kotfu May 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. As I think about this more, I think it would be wise to put both of those regexes into the StatementParser class, and to switch the invalid_alias_pattern to be valid_alias_pattern. That way the logic in using both regexes is the same, i.e. if match: then it's valid. And the logic of generating both patterns would also be encapsulated.

Provide a new is_valid_command() method on StatementParser to determine whether a string of characters could be a valid command. That means it can’t include any redirection, quote chars, whitespace, or terminator characters. This method is used when someone tries to create an alias, to ensure when we try and parse the alias that it will actually parse.

This nicely encapsulates and standardizes all the logic for parsing and expansion into the StatementParser class.

Also fix a bug in the regex to match valid command names, and add a bunch of new unit tests to ensure the bug stays fixed.
@kotfu kotfu added the bug label May 8, 2018
@kotfu kotfu added this to the 0.9.0 milestone May 8, 2018
@kotfu
Copy link
Member Author

kotfu commented May 8, 2018

Addressed both of @tleonhardt's comments in prior review. Merging to master.

@kotfu kotfu merged commit cc45557 into master May 8, 2018
@kotfu kotfu deleted the ignore_identchars branch May 8, 2018 03:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants