diff --git a/bumpversion/utils.py b/bumpversion/utils.py index f872f230..b3dd64ad 100644 --- a/bumpversion/utils.py +++ b/bumpversion/utils.py @@ -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, diff --git a/tests/test_cli.py b/tests/test_cli.py index fbbd38d8..c420aac7 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -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()