Bug 432679 - Kcron misinterprets certain crontab comments as jobs
Summary: Kcron misinterprets certain crontab comments as jobs
Status: RESOLVED FIXED
Alias: None
Product: kcron
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: Gentoo Packages Linux
: NOR minor
Target Milestone: ---
Assignee: Gary Meyer
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-02-09 09:05 UTC by Raul
Modified: 2023-12-24 11:17 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Raul 2021-02-09 09:05:33 UTC
SUMMARY
Kcron misinterprets some crontab comments as jobs, ignoring the hash character.

STEPS TO REPRODUCE
1. Close Kcron/System Settings if it's already running.
2. Using the command line, edit your user's crontab (crontab -e).
3. Write this comment at the end of the file:
# - - - * randomtext
4. Close the editor, wait for your crontab to be updated and open Kcron.

OBSERVED RESULT
In Kcron, the comment appears as a disabled job, with "- - - *" as scheduling and "randomtext" as command. It completely ignores the # hash character.

EXPECTED RESULT
As any comment, it should never be shown as a job, but ignored or used as "description" if it's right above a given job.

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Gentoo (profile default/linux/amd64/17.1/desktop/plasma stable, kernel 5.4.92)
KDE Plasma Version: 5.20.5
KDE Frameworks Version: 5.77.0
Qt Version: 5.15.2
Kcron version (as shown in package manager): 20.08.3:5

ADDITIONAL INFORMATION
Comment 1 Bug Janitor Service 2023-11-14 22:51:11 UTC
A possibly relevant merge request was started @ https://invent.kde.org/system/kcron/-/merge_requests/22
Comment 2 Albert Astals Cid 2023-12-24 11:17:26 UTC
Git commit 9abf45fa8bd27a22739a721641e5b8dd679a9bdc by Albert Astals Cid, on behalf of Cássio Sousa.
Committed on 24/12/2023 at 12:17.
Pushed by aacid into branch 'master'.

Improvements in the handling of crontab comments

Improvements in the handling of crontab comments include appending all commented lines above a cron expression and discarding previous ones if there is an enter.

Works situations
```sh
#- - - * randomtext abc
#5 * * * *       /home/ubuntu/teste.sh


#- - - * randomtext abc
5 * * * *       /home/ubuntu/teste.sh
#- - - * randomtext abc
#5 * * * *       /home/ubuntu/teste.sh
```

```sh
#- - - * randomtext abc
#5 * * * *       /home/ubuntu/teste.sh

#- - - * randomtext abc
5 * * * *       /home/ubuntu/teste.sh
```

```sh
# another comment
#- - - * randomtext abc
5 * * * *       /home/ubuntu/teste.sh
```

Before:
| header | header |
| ------ | ------ |
|  ![sk4](/uploads/c612c20090ad6bf522e16d222f4c3256/sk4.png)      |   ![sk5](/uploads/8a54851d6cc5d0fdc911ec5df157fe97/sk5.png)     |


After
| header | header |
| ------ | ------ |
|  ![sk6](/uploads/790890284229d38e6676d04ec1643dbe/sk6.png)      |   ![sk7](/uploads/b48bb6c8ee32fd96d13445a8dfbff66d/sk7.png)     |



Another example

```sh
#- - - * randomtext abc
#5 * * * *       /home/ubuntu/teste.sh
#- - - * randomtext abc
5 * * * *       /home/ubuntu/teste.sh

#teste abc
#\  * * *       /home/ubuntu/kde/src/kcron/Messages.sh
#testes comentários
10 * * * *       /home/ubuntu/kde/src/kcron/Messages.sh
```
![image](/uploads/452bfdd47170c2d82b0ddf97e775e908/image.png)

M  +15   -24   src/crontablib/ctcron.cpp

https://invent.kde.org/system/kcron/-/commit/9abf45fa8bd27a22739a721641e5b8dd679a9bdc