diff --git a/src/Controller/TimesheetAbstractController.php b/src/Controller/TimesheetAbstractController.php index af67bc89..9aebb71f 100644 --- a/src/Controller/TimesheetAbstractController.php +++ b/src/Controller/TimesheetAbstractController.php @@ -183,6 +183,11 @@ abstract class TimesheetAbstractController extends AbstractController $entry->setActivity($activity); } + if ($request->query->get('description')) { + $description = $request->query->get('description'); + $entry->setDescription($description); + } + if ($request->query->get('tags')) { foreach ($this->getTags($tagRepository, $request->query->get('tags')) as $tag) { $entry->addTag($tag); diff --git a/tests/Controller/TimesheetControllerTest.php b/tests/Controller/TimesheetControllerTest.php index d97778ae..951c54bb 100644 --- a/tests/Controller/TimesheetControllerTest.php +++ b/tests/Controller/TimesheetControllerTest.php @@ -497,6 +497,60 @@ class TimesheetControllerTest extends ControllerBaseTest $this->assertEquals(['one', 'two', 'three'], $timesheet->getTagsAsArray()); } + public function testCreateActionWithDescription() + { + $client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN); + + $this->request($client, '/timesheet/create?description=Lorem%20Ipsum'); + $this->assertTrue($client->getResponse()->isSuccessful()); + + $form = $client->getCrawler()->filter('form[name=timesheet_edit_form]')->form(); + $client->submit($form, [ + 'timesheet_edit_form' => [ + 'hourlyRate' => 100, + 'project' => 1, + 'activity' => 1, + ] + ]); + + $this->assertIsRedirect($client, $this->createUrl('/timesheet/')); + $client->followRedirect(); + $this->assertTrue($client->getResponse()->isSuccessful()); + $this->assertHasFlashSuccess($client); + + $em = $this->getEntityManager(); + /** @var Timesheet $timesheet */ + $timesheet = $em->getRepository(Timesheet::class)->findAll()[0]; + $this->assertEquals('Lorem Ipsum', $timesheet->getDescription()); + } + + public function testCreateActionWithDescriptionHtmlInjection() + { + $client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN); + + $this->request($client, '/timesheet/create?description=Some text">HelloWorld<%2Fbold>'); + $this->assertTrue($client->getResponse()->isSuccessful()); + + $form = $client->getCrawler()->filter('form[name=timesheet_edit_form]')->form(); + $client->submit($form, [ + 'timesheet_edit_form' => [ + 'hourlyRate' => 100, + 'project' => 1, + 'activity' => 1, + ] + ]); + + $this->assertIsRedirect($client, $this->createUrl('/timesheet/')); + $client->followRedirect(); + $this->assertTrue($client->getResponse()->isSuccessful()); + $this->assertHasFlashSuccess($client); + + $em = $this->getEntityManager(); + /** @var Timesheet $timesheet */ + $timesheet = $em->getRepository(Timesheet::class)->findAll()[0]; + $this->assertEquals('Some text">HelloWorld', $timesheet->getDescription()); + } + public function testEditAction() { $client = $this->getClientForAuthenticatedUser();