Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

empty version (or project (?)) cause regex matching crash #85

Closed
svenevs opened this issue Jan 30, 2019 · 7 comments
Closed

empty version (or project (?)) cause regex matching crash #85

svenevs opened this issue Jan 30, 2019 · 7 comments
Labels
type: bug 🪲 Something is wrong
Milestone

Comments

@svenevs
Copy link

svenevs commented Jan 30, 2019

Found what I think is a bug in the header parsing. This project commented out their version number resulting in an empty Version in the header to the objects.inv:

sven:/tmp> wget https://bootstrap-datepicker.readthedocs.io/en/master/objects.inv
sven:/tmp> head -4 objects.inv 
# Sphinx inventory version 2
# Project: bootstrap-datepicker
# Version: 
# The remainder of this file is compressed using zlib.
sven:/tmp> sphobjinv convert plain objects.inv 
 

Error: Unrecognized file format

If you do it directly, you get information that seems to mean that you assume Version and Project actually have values after them (and apparently they don't need to):

>>> import sphobjinv as soi
>>> inv = soi.Inventory('objects.inv')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<attrs generated init d264050f79466679381c6c61e7053ac5e806eac0>", line 16, in __init__
  File "/usr/local/lib/python3.6/site-packages/sphobjinv/inventory.py", line 365, in __attrs_post_init__
    self._general_import()
  File "/usr/local/lib/python3.6/site-packages/sphobjinv/inventory.py", line 598, in _general_import
    import_errors[st]):
  File "/usr/local/lib/python3.6/site-packages/sphobjinv/inventory.py", line 612, in _try_import
    p, v, o = import_fxn(src)
  File "/usr/local/lib/python3.6/site-packages/sphobjinv/inventory.py", line 659, in _import_plaintext_fname
    return self._import_plaintext_bytes(b_plain)
  File "/usr/local/lib/python3.6/site-packages/sphobjinv/inventory.py", line 629, in _import_plaintext_bytes
    b_res = pb_version.search(b_str).group(HeaderFields.Version.value)
AttributeError: 'NoneType' object has no attribute 'group'

I think you want to change .+ to be .*?

(?P<{}>.+?) # Lazy rest of line is the project name

(?P<{}>.+?) # Lazy rest of line is the version

And then it will return you empty strings?

@bskinn
Copy link
Owner

bskinn commented Jan 30, 2019

Never thought anybody'd build docs without a version!

You're right, that regex for version will definitely need to be changed, as you indicated -- will be interesting to see how deep into the codebase that assumption runs.

If Sphinx allows an empty project, then yeah, that'll need to be changed, too.

Thanks for reporting this! I'll get a bugfix update out as soon as I can.

@bskinn bskinn added the type: bug 🪲 Something is wrong label Jan 30, 2019
@bskinn bskinn added this to the v2.0.1 milestone Jan 30, 2019
@bskinn
Copy link
Owner

bskinn commented Jan 30, 2019

On a quick test, it looks like Sphinx automatically sets project = "Python" if it is not defined in conf.py. I'll make a more thorough test of Sphinx versions back through 1.0 to be sure, though. BUT, if project = "" is explicitly set in conf.py, Sphinx honors it and project indeed is null in the objects.inv

So, I think only the possibility of a blank version needs to be accounted for.

I'll have to fix both!

bskinn added a commit that referenced this issue Jan 30, 2019
@svenevs svenevs changed the title empty version (or project (?)) cause regex mashing crash empty version (or project (?)) cause regex matching crash Jan 31, 2019
@svenevs
Copy link
Author

svenevs commented Jan 31, 2019

Never thought anybody'd build docs without a version!

Hehehehe. Bugs like this are kind of fun though, I had no idea sphinx defaulted to project = "Python". Seems like you've got this under wraps, but let me know if you want any testing from me! This project has served me very well over the years 🙂

@bskinn
Copy link
Owner

bskinn commented Jan 31, 2019

This project has served me very well over the years 🙂

I haz a uzer! 😲 😃 In retrospect, I should probably have picked a name that was easier to pronounce.....

Seems like you've got this under wraps, but let me know if you want any testing from me!

Yep, the fix was pretty much as simple as you indicated, changing to .*. I added some new test inventories to the matrix (1, 2, 3) to cover, and that about did it.

Of course, updating my virtual environment to run the tests revealed that one of my other projects, which is a testing dependency of sphobjinv, is incompatible with attrs v18.2, due to some change in how attrs handles slots=True. So, I should probably cut a release of that project first, so I can better confirm dependency compatibility for v2.0.1 here.... Whee!

bskinn added a commit that referenced this issue Feb 1, 2019
Blacken, adding helper scripts. Closes #86.

Switch Travis from flake8 check to black check. Improve
the filtering in the 'scripts:' section for the things
only to do on 3.6 (black check, doctest, codecov).

Due to stdio-mgr blowing up on attrs>=18.1, needed to
add a pip --force-reinstall to ensure attrs is downgraded.
(Appears that Travis envs come with attrs==latest by default?)

Adjust project and version regexes to allow empty fields.
Add dummy inventories to the test resources to ensure they get
handled ok. Closes #85.
@bskinn
Copy link
Owner

bskinn commented Feb 1, 2019

Keep an eye out for a v2.0.1rc1 release here soon, it'll get this fix out there before I take care of the stdio-mgr problem. pip install -U --pre sphobjinv should grab it once I get it up to PyPI.

@bskinn bskinn closed this as completed in e3c9d16 Feb 1, 2019
@bskinn
Copy link
Owner

bskinn commented Feb 1, 2019

v2.0.1rc1 is published, @svenevs

@bskinn
Copy link
Owner

bskinn commented Jan 27, 2020

Apologies for this fix sitting on rc1 for most of a year, @svenevs -- FYI, a final v2.0.1 is now up on PyPI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug 🪲 Something is wrong
Projects
None yet
Development

No branches or pull requests

2 participants