Skip to content

various errors resulting from str.startswith() matching empty string #77

Description

@rrotter

Several places where str.startswith() is used misparse when "" is used as a parameter, because it matches the empty string (""):

  • ip addr "" is parsed as ip addr show
  • ip "" is parsed as ip addr

What iproute2 does:

% ip a ""
Command "" is unknown, try "ip address help".
% ip ""
Object "" is unknown, try "ip help".

Admittedly this is a degenerate case, and probably isn't too high of a priority.

I started working on these piecemeal, but the patch was getting messy. In most cases making sure that the string isn't "" is sufficient, but I found at least one case where that's still too lenient (ip link s is not allowed by iproute2 in my testing, but maddeningly, ip addr s is!!)

I may submit a patch for this, but probably not soon. I'd probably work on refactoring or unit tests first.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions