Skip to content

Commit

Permalink
Fix username detection with \W characters
Browse files Browse the repository at this point in the history
  • Loading branch information
devtronic committed Nov 3, 2022
1 parent b3516b1 commit 40f9cda
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

# v1.1.2
Fixes:
- Usernames can contain `\W` characters [PR #3](https://github.com/mintware-de/native-cron/pull/3)

# v1.1.1
Fixes:
- Crontabs must end with an empty line [PR #2](https://github.com/mintware-de/native-cron/pull/2)
Expand Down
2 changes: 1 addition & 1 deletion src/Content/CronJobLine.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class CronJobLine implements CrontabLineInterface
{
public const PATTERN_WITH_USER = '~^(?P<datetime>'.DateTimeDefinition::PATTERN.')\s*(?P<user>\w+)\s*(?P<command>.+)$~';
public const PATTERN_WITH_USER = '~^(?P<datetime>'.DateTimeDefinition::PATTERN.')\s*(?P<user>[^\s]+)\s*(?P<command>.+)$~';
public const PATTERN_WITHOUT_USER = '~^(?P<datetime>'.DateTimeDefinition::PATTERN.')\s*(?P<command>.+)$~';

private bool $includeUser;
Expand Down
7 changes: 7 additions & 0 deletions tests/Content/CronjobLineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,13 @@ public function testBuildAdvanced(): void
self::assertEquals($line, $cronjobLine->build());
}

public function testUserWithDashes(): void
{
$line = '* * * * * www-data command';
$cronjobLine = new CronJobLine($line, true);
self::assertEquals('www-data', $cronjobLine->getUser());
}

private function checkEmptyValues(CronJobLine $cronjobLine): void
{
$dateTimeDefinition = $cronjobLine->getDateTimeDefinition();
Expand Down

0 comments on commit 40f9cda

Please sign in to comment.