podhmo / python-node-semver

python version of node-semver
MIT License
21 stars 15 forks source link

Unhandled AttributeError in parse() call #42

Open claudiamarcubina opened 4 years ago

claudiamarcubina commented 4 years ago

Calling parse(version, loose) can return None when the provided version is not a strictly semantic version. This case is not handled when parse(version, loose) is called from valid(version, loose):

# semver.__init__.py

def parse(version, loose):
    if loose:
        r = regexp[LOOSE]
    else:
        r = regexp[FULL]
    m = r.search(version)
    if m:
        return semver(version, loose)
    else:
        return None # this can return None

def valid(version, loose):
    v = parse(version, loose)
    if v.version: # here it is just supposed that v has 'version' attribute
        return v
    else:
        return None