Skip to content

Escape dollar sign for saving content into crontab #26462

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

Merged
merged 3 commits into from
Feb 9, 2020
Merged

Escape dollar sign for saving content into crontab #26462

merged 3 commits into from
Feb 9, 2020

Conversation

Erfans
Copy link
Contributor

@Erfans Erfans commented Jan 20, 2020

The crontab contents can contain dollar sign (e.g. $(date)).
The current code does not escape it which transform it to actual values.
In this commit a replacement to escape dollar sign is added to the previous replacements.

an example in crontab could be
mysqldump db > db-$(date +%F).sql

Description (*)

Class lib/internal/Magento/Framework/Crontab/CrontabManager.php function save already replace couple of special characters '%' and '"'. I added a new entry into the replacement to escape dollar sign as well. i.e. convert $ to \$.

Manual testing scenarios (*)

  1. Add a new entry to crontab with dollar sign, e.g: mysqldump -uroot DB >/home/backups/$(date +%F)_db.sql
  2. Run the cron install command in the magento root directory: bin\magento cron:install
  3. check the content of the crontab. The $(date +%F) is transformed to actual date string. bin\magento cron:remove has the same effect as well.

This pull request should fix the conversion, i.e. after bin\magento cron:install the content of the other parts with dollar sign should stay intact.

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds are green)

The crontab contents can contain dollar sign (e.g. $(date)).
The current code does not escape it which transform it to actual values.
In this commit a replacement to escape dollar sign is added to the previous replacements.
@m2-assistant
Copy link

m2-assistant bot commented Jan 20, 2020

Hi @Erfans. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

For more details, please, review the Magento Contributor Guide documentation.

@ihor-sviziev ihor-sviziev self-assigned this Jan 21, 2020
Copy link
Contributor

@ihor-sviziev ihor-sviziev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Erfans,
Unfortunately steps to reproduce isn't clear how to test it. Could you explain 1st step more detailed?

In general your changes looks good.
Could you cover your changes with unit or integration test, so we'll not brake this functionality in future?

@Erfans
Copy link
Contributor Author

Erfans commented Jan 24, 2020

Hi @ihor-sviziev

for reproducing step 1:

  1. Login to the machine that M2 is installed on it.
  2. Manually modify the crontab (with the user of web server)
    e.g.
    crontab -e -uwww-data
  3. insert a new line with a content that contains dollar sign ($)
    e.g.
    0 0 * * * mysqldump db > db-$(date +%F).sql
  4. save the crontab
  5. install the magento cron job bin\magento cron:install
  6. check the crontab
    crontab -l -uwww-data

the $(date +%F) will be transformed to actual date string

for unit test perhaps I can add it in the next week.

@ihor-sviziev
Copy link
Contributor

@Erfans ok, so we’ll wait for test coverage

@ihor-sviziev ihor-sviziev added the Auto-Tests: Not Covered Changes in Pull Request requires coverage by auto-tests label Jan 28, 2020
@engcom-Echo
Copy link
Contributor

I will take care of test coverage.

@engcom-Echo engcom-Echo self-assigned this Jan 29, 2020
@engcom-Echo engcom-Echo added Auto-Tests: Covered All changes in Pull Request is covered by auto-tests and removed Auto-Tests: Not Covered Changes in Pull Request requires coverage by auto-tests labels Jan 29, 2020
@magento-engcom-team
Copy link
Contributor

Hi @ihor-sviziev, thank you for the review.
ENGCOM-6753 has been created to process this Pull Request

@magento-engcom-team
Copy link
Contributor

@Erfans thank you for contributing. Please accept Community Contributors team invitation here to gain extended permissions for this repository.

@engcom-Alfa
Copy link
Contributor

✔️ QA Passed

@m2-assistant
Copy link

m2-assistant bot commented Feb 9, 2020

Hi @Erfans, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants