google-research / arxiv-latex-cleaner

arXiv LaTeX Cleaner: Easily clean the LaTeX code of your paper to submit to arXiv
Apache License 2.0
5.04k stars 318 forks source link

Fixes path split bug and add more tests for `_search_reference` #55

Closed aditya95sriram closed 2 years ago

aditya95sriram commented 2 years ago

Sequel to #25, added more tests, discovered a bug in the process, fixed the bug, added some more tests.

In case you're curious about the bug, turns out os.path.split only splits a path into two parts. So os.path.split("long/path/to") will yield "long/path", "to". And, earlier we were iterating over the result of os.path.split expecting to get all the parts one by one, i.e. ["long", "path", "to"]. Now, we first collect all the path fragments and then loop over them.

fragments = []
cur_head = os.path.dirname(filename)
while cur_head:
  cur_head, tail = os.path.split(cur_head)
  fragments.insert(0, tail)  # insert at the beginning
jponttuset commented 2 years ago

Thanks @aditya95sriram!