Skip to content

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

Closed

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.

Activity

  1. changed the title [-]various errors caused resulting from `str.startswith()` matching empty string[/-] [+]various errors resulting from `str.startswith()` matching empty string[/+] on Mar 13, 2026
  2. brona commented on Mar 28, 2026

    @brona
    Owner

    I think 28e8dc3 should do it, feel free to have a look / review.

  3. added a commit that references this issue on Mar 29, 2026
    28e8dc3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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