PyCQA / PyCQA/bandit

Extra spaces added by bandit.code.utils.concat_string

Open
#1,009 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
8.3k
Forks
836
Avg merge
5d 3h
Merged PRs (30d)
1

Description

Describe the bug

When calling bandit.code.utils.concat_string extra spaces are added between the strings which are concatenated.

Reproduction steps
import ast
from bandit.core import utils

# Create a simple string concatenation
bin_op = ast.parse('"Hello" + "World"').body[0].value

# Manually fix-up the node
bin_op._bandit_parent = None

node, string = utils.concat_string(bin_op)

assert string == "HelloWorld", 'Got %r' % (string, )
Expected behavior

Extra spaces should not be added.

Remove the space used to .join() the strings on https://github.com/PyCQA/bandit/blob/72fa5a7496caa89f21ace353d038754dbddf9a91/bandit/core/utils.py#L305

Bandit version

1.7.5 (Default)

Python version

3.9

Additional context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in bandit/core/utils.py at concat_string(), especially the join operation referenced in the issue. Reproduce the behavior with the provided Python snippet and add or update a focused test for concatenating "Hello" and "World". Done means the returned string is "HelloWorld" without an inserted space.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.