AST-text-analysis icon indicating copy to clipboard operation
AST-text-analysis copied to clipboard

IndexError: string index out of range

Open zavgorodnii opened this issue 9 years ago • 1 comments

Good day! Found a bug which doesn't let you build a tree successfully on certain data.

https://github.com/msdubov/AST-text-analysis/blob/master/east/asts/easa.py#L259

while string[i + h] == string[j + h]:
    h += 1

For this line there is a condition when you get the following error:

File "test.py", line 547, in main
    ast = base.AST.get_ast(strings)
  File "/home/oopcode/projects/.env/local/lib/python2.7/site-packages/east/asts/base.py", line 17, in get_ast
    return ast_cls(strings_collection)
  File "/home/oopcode/projects/.env/local/lib/python2.7/site-packages/east/asts/easa.py", line 19, in __init__
    self.lcptab = self._compute_lcptab(self.string, self.suftab)
  File "/home/oopcode/projects/.env/local/lib/python2.7/site-packages/east/asts/easa.py", line 259, in _compute_lcptab
    while string[i + h] == string[j + h]:
IndexError: string index out of range

I had to add the following to source code to make the whole thing work:

while (str_len < i + h or str_len < j + h) and string[i + h] == string[j + h]:
    h += 1

I can send you the file with problematic data (if you want to).

zavgorodnii avatar Jun 30 '15 14:06 zavgorodnii

Hi Andrew,

thanks for reporting this. Yes, please send me the problematic data, I'd like to try reproducing this issue.

It would also be cool if you contributed your bugfix as a pull request to this repository.

mikhaildubov avatar Jul 06 '15 11:07 mikhaildubov