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

Constant strings interpreted as regex #61

Closed
kdeldycke opened this issue Aug 29, 2023 · 1 comment · Fixed by #63
Closed

Constant strings interpreted as regex #61

kdeldycke opened this issue Aug 29, 2023 · 1 comment · Fixed by #63
Labels
bug Something isn't working

Comments

@kdeldycke
Copy link
Collaborator

kdeldycke commented Aug 29, 2023

  • bump-my-version version: 0.9.3
  • Python version: 3.11.15
  • Operating System: macOS

Description

In some circumstances, while I deactivated regex mode everywhere (both in config file and on CLI invokation), the search string gets interpreted as a regex and has unwanted side-effects.

What I Did

Starting from a changelog.md file containing:

# Changelog

## [0.0.1 (unreleased)](https://cool.url)

- Test unreleased package.

With a pyproject.toml file alongside containing:

[tool.bumpversion]
current_version = "0.0.1"
allow_dirty = true

[[tool.bumpversion.files]]
filename = "./changelog.md"
no_regex = true
search = "(unreleased)"
replace = "({now:%Y-%m-%d})"

Now let's invoke this CLI:

$ bump-my-version replace --verbose --dry-run --no-regex --no-configured-files --search "(unreleased)" --replace "({now:%Y-%m-%d})" ./changelog.md
Starting BumpVersion 0.9.3                                                                                                                                                                                          
Reading config file pyproject.toml:                                                                                                                                                                                 
Parsing version '0.0.1' using regexp '(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)'                                                                                                                               
Parsed the following values: major=0, minor=0, patch=1                                                                                                                                                              
Asserting files ./changelog.md contain the version string...                                                                                                                                                        
Found 're.compile('(unreleased)', re.MULTILINE|re.DOTALL)' in ./changelog.md at line 3: unreleased                                                                                                                  
Would change file ./changelog.md:                                                                                                                                                                                   
*** before ./changelog.md                                                                                                                                                                                           
--- after ./changelog.md                                                                                                                                                                                            
***************                                                                                                                                                                                                     
*** 1,5 ****                                                                                                                                                                                                        
  # Changelog                                                                                                                                                                                                       
                                                                                                                                                                                                                    
! ## [0.0.1 (unreleased)](https://cool.url)                                                                                                                                                                         
                                                                                                                                                                                                                    
! - Test unreleased package.                                                                                                                                                                                        
--- 1,5 ----                                                                                                                                                                                                        
  # Changelog                                                                                                                                                                                                       
                                                                                                                                                                                                                    
! ## [0.0.1 ((2023-08-29))](https://cool.url)                                                                                                                                                                       
                                                                                                                                                                                                                    
! - Test (2023-08-29) package.     

You can see here how the (unreleased) search string is interpreted as a regex and has unwanted side effect in changelog.md file.

I expect here to have the final result of that file to be:

# Changelog                                                                                                                                                                                                       
                                                                                                                                                                                                                    
## [0.0.1 (2023-08-29)](https://cool.url)                                                                                                                                                                       
                                                                                                                                                                                                                    
- Test unreleased package.     

Instead of:

# Changelog                                                                                                                                                                                                       
                                                                                                                                                                                                                    
## [0.0.1 ((2023-08-29))](https://cool.url)                                                                                                                                                                       
                                                                                                                                                                                                                    
- Test (2023-08-29) package.     

I have a hard time understanding what's happening.

Maybe there is a difference between in the way strings passed in the CLI are not parsed like those in the config file.

Maybe duplicating the replace action in both the config file and the CLI is messing with some internals.

Or maybe the --no-configured-files is not well-named, as I expect it to ignore the directives from any configuration file found. In which case what I am looking for is probably a --no-config option.

@coordt coordt added the bug Something isn't working label Sep 4, 2023
coordt added a commit that referenced this issue Sep 4, 2023
- Fixes #61
- Config now includes `resolved_filemap` property
- resolved filemap exapands all globs
- Config now includes `files_to_modify` property
- files to modify resolves inclusions and exclutions
- Improved Config.add_files property
@coordt coordt linked a pull request Sep 4, 2023 that will close this issue
@coordt coordt closed this as completed in #63 Sep 5, 2023
@kdeldycke
Copy link
Collaborator Author

Just tested 0.10.0. I confirm this issue has been fixed upstream. Thanks a lot @coordt for the fast fix and release! 💪

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants