Skip to content

Index out of range error in autoflake.fix_code #324

@gabe-sherman

Description

@gabe-sherman

When the following program is provided with a specially crafted input, this leads to an index out of range error in the extract_package_name function at line 264 in autoflake.py. This seems to stem from incorrect handling of a carriage return character in the input text(\r).

import autoflake

autoflake.fix_code("import t\rs\nimport test\nimport0")

Setup Info

Version: 2.31
Commit: b87ff10

Trace Report

Traceback (most recent call last):
  File "rep.py", line 3, in <module>
    autoflake.fix_code("import t\rs\nimport test\nimport0")
  File "python3.10/site-packages/autoflake.py", line 924, in fix_code
    "".join(
  File "python3.10/site-packages/autoflake.py", line 622, in filter_code
    result = filter_unused_import(
  File "python3.10/site-packages/autoflake.py", line 699, in filter_unused_import
    package = extract_package_name(line)
  File "python3.10/site-packages/autoflake.py", line 264, in extract_package_name
    word = line.split()[1]
IndexError: list index out of range

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions