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

Improve handling nosec for multi-line strings #915

Merged
merged 1 commit into from
Feb 27, 2023

Commits on Feb 27, 2023

  1. Improve handling nosec for multi-line strings

    This commit improves handling nosecs
    in multi-line strings, like:
    
    1. nosec_not_working = f"""
    2.     SELECT * FROM {table}
    3. """  # nosec
    
    Before this change, bandit was checking if there is
    a nosec in line 1. Now, it searches for nosec in all
    lines of the expression.
    
    In python 3.7, linerange for a multiline expression is sqeezed to
    first line. Thus, if nosec is set  in the second or further line
    then it is not taken into account by bandit.
    
    This commit also moves detecting nosec without test number
    to test phase from "pre-visit" phase.
    It may increase the time of performing checks but avoids
    counting the same nosec mark multiple times.
    "pre-visit" phase is run separately for each part of multi-line
    string split by FormattedValue items. Thus for the above example,
    it would be run twice, the first time for "\n    SELECT * FROM "
    and the second time for "\n" making the nosec being counted twice.
    
    Resolves: PyCQA#880
    kfrydel committed Feb 27, 2023
    Configuration menu
    Copy the full SHA
    1a27530 View commit details
    Browse the repository at this point in the history