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

Issue/198 inconsistent search replace #262

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions bumpversion/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,7 @@ def contains(self, search):
if len(lookbehind) > len(search_lines):
lookbehind = lookbehind[1:]

if (
search_lines[0] in lookbehind[0]
and search_lines[-1] in lookbehind[-1]
and search_lines[1:-1] == lookbehind[1:-1]
):
if "\n".join(search_lines) in "\n".join(lookbehind):
logger.info(
"Found '%s' in %s at line %s: %s",
search,
Expand Down
45 changes: 45 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1923,6 +1923,51 @@ def test_non_matching_search_does_not_modify_file(tmpdir):
assert config_content in tmpdir.join(".bumpversion.cfg").read()


def test_non_matching_search_does_not_modify_file_multiline(tmpdir):
"""
Verify that a multiline search with trailing characters on the first line or leading characters on the last line does not
match (#198).
"""
tmpdir.chdir()

version_content = dedent(
"""
multi TRAILING
line
matching 1.0.0

multi
line
LEADING matching 1.0.0
"""
)

config_content = dedent(
"""
[bumpversion]
current_version = 1.0.0

[bumpversion:file:VERSION]
search = multi
line
matching
replace = REPLACEMENT
"""
)

tmpdir.join("VERSION").write(version_content)
tmpdir.join(".bumpversion.cfg").write(config_content)

with pytest.raises(
exceptions.VersionNotFoundException,
match="Did not find 'multi\nline\nmatching' in file: 'VERSION'"
):
main(['patch'])

assert version_content == tmpdir.join("VERSION").read()
assert config_content in tmpdir.join(".bumpversion.cfg").read()


def test_search_replace_cli(tmpdir):
tmpdir.join("file89").write("My birthday: 3.5.98\nCurrent version: 3.5.98")
tmpdir.chdir()
Expand Down