Skip to content

feat: support gsub_file erroring if gsub doesn't change anything, and add gsub_file!#877

Merged
rafaelfranca merged 4 commits into
rails:mainfrom
G-Rath:gsub_file-error-on-no-change
Jul 18, 2025
Merged

feat: support gsub_file erroring if gsub doesn't change anything, and add gsub_file!#877
rafaelfranca merged 4 commits into
rails:mainfrom
G-Rath:gsub_file-error-on-no-change

Conversation

@G-Rath

@G-Rath G-Rath commented Feb 23, 2024

Copy link
Copy Markdown
Contributor

🌈


This is a straw-person solution for #874 - overall I think it's not bad but expect changes to be requested; in particular, the option name is pretty verbose so happy if someone wants to suggest an alternative though to me really its about having gsub_file!.

A bonus to this is that anything using gsub_file also supports this behaviour such as comment_lines and uncomment_lines - I think it would be nice to have bang versions of such methods too but want to get the core behaviour/implementation nailed down first.

Resolves #874

Comment thread lib/thor/actions/file_manipulation.rb Outdated
@G-Rath G-Rath force-pushed the gsub_file-error-on-no-change branch from 4f92183 to 8eae746 Compare February 29, 2024 19:05
@G-Rath

G-Rath commented Feb 29, 2024

Copy link
Copy Markdown
Contributor Author

@rafaelfranca can you let me know if you'd be interested in having bang methods for the other file manipulations? (either in this PR or another one)

@G-Rath G-Rath requested a review from rafaelfranca February 29, 2024 19:09
@G-Rath G-Rath force-pushed the gsub_file-error-on-no-change branch from 8eae746 to 620b685 Compare February 29, 2024 19:10
@G-Rath

G-Rath commented May 3, 2024

Copy link
Copy Markdown
Contributor Author

@rafaelfranca could I get a re-review on this please?

@G-Rath

G-Rath commented Oct 8, 2024

Copy link
Copy Markdown
Contributor Author

@rafaelfranca would you mind re-reviewing this? we'd really like to get it landed and I think I've addressed your concerns 🙂

@G-Rath G-Rath force-pushed the gsub_file-error-on-no-change branch from 54bc9de to ae14cb1 Compare March 20, 2025 21:40
@G-Rath

G-Rath commented Mar 20, 2025

Copy link
Copy Markdown
Contributor Author

@rafaelfranca @yahonda would it be possible to have this reviewed, or at least have the need-work label removed?

@rafaelfranca rafaelfranca merged commit 048bbdd into rails:main Jul 18, 2025
@G-Rath

G-Rath commented Jul 18, 2025

Copy link
Copy Markdown
Contributor Author

@rafaelfranca thanks! I have actually found it useful to have bang methods for some of the other file modification functions - would you be happy to accept a PR for those too?

@rafaelfranca

Copy link
Copy Markdown
Member

Yes! Happy to

@G-Rath

G-Rath commented Jul 21, 2025

Copy link
Copy Markdown
Contributor Author

@rafaelfranca I've opened #908 adding a bang version of insert_into_file - I realized after doing that it doesn't actually make sense to have versions of prepend_into_file and append_into_file since they should never be able to fail unless the file doesn't exist or is not writable, which already causes an error

bmwiedemann pushed a commit to bmwiedemann/openSUSE that referenced this pull request Jul 24, 2025
https://build.opensuse.org/request/show/1295381
by user dancermak + dimstar_suse
- 1.4.0:
## What's Changed
* Lazy-load YAML for performance improvement in rails/thor#892
* Fix encoding error when displaying diffs in rails/thor#898
* Fix unsafe shell command construction (security issue) in rails/thor#897 (bsc#1246809)
* Support `git difftool`-style merge tool identifiers in rails/thor#900
* Add `gsub_file!` and make `gsub_file` fail if no substitutions occur in rails/thor#877
## Security
* CVE-2025-54314: Fixed a vulnerability where user input could result in unsafe shell command execution. (bsc#1246809)
## New Contributors
* @hlascelles made their first contribution in rails/thor#893
**Full Changelog**: https://github.com/rail
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ability to have gsub_file error if it didn't gsub anything

2 participants