release-engineering/kobo

rpmlib.parse_nvra() should "strip" more

lkocman opened this issue · 2 comments

Hello,

I'd expect that if rpmlib.parse_nvra() would call strip() or any other tool to get rid of possible newline character on the end of string.

I expect that "\n" isn't valid arch anyway.

Execution:
lkocman@xxx> python -c 'from kobo.shortcuts import run; import kobo.rpmlib; print kobo.rpmlib.parse_nvra(run("rpm -q rhsm-tools")[1])'

Actual results:
{'src': False, 'name': 'rhsm-tools', 'epoch': '', 'version': '1.26', 'release': '1.el6eng', 'arch': 'noarch\n'}
lkocman@rcm-dev:tmp>

Expected results (execution is enforcing .strip() on rpm output)
lkocman@rcm-dev:tmp> python -c 'from kobo.shortcuts import run; import kobo.rpmlib; print kobo.rpmlib.parse_nvra(run("rpm -q rhsm-tools")[1].strip())'
{'src': False, 'name': 'rhsm-tools', 'epoch': '', 'version': '1.26', 'release': '1.el6eng', 'arch': 'noarch'}
lkocman@rcm-dev:tmp>

Shouldn't you rather pass valid input in the first place? I don't like the idea of library functions trying hard to accept all inputs and guess what the caller really wanted. It tends to result in sprawling complexity.

Closing: my opinion is unchanged since last comment, the job of parse_nvra is to parse a valid NVRA string into components. If you provide it something other than a valid NVRA, I don't think it's fair to expect correct results. I would be more in favor of making it crash than making it try to coerce the input into what the caller may have wanted.