Skip to content

Commit

Permalink
Merge branch 'master' of github.com:LitusProject/Litus
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrodevog committed Oct 28, 2023
2 parents c7aa050 + ed3c632 commit c1f3fa7
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 6 deletions.
12 changes: 6 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

72 changes: 72 additions & 0 deletions module/TicketBundle/Component/Validator/UrlValid.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php
/**
* Litus is a project by a group of students from the KU Leuven. The goal is to create
* various applications to support the IT needs of student unions.
*
* @author Niels Avonds <[email protected]>
* @author Karsten Daemen <[email protected]>
* @author Koen Certyn <[email protected]>
* @author Bram Gotink <[email protected]>
* @author Dario Incalza <[email protected]>
* @author Pieter Maene <[email protected]>
* @author Kristof Mariën <[email protected]>
* @author Lars Vierbergen <[email protected]>
* @author Daan Wendelen <[email protected]>
* @author Mathijs Cuppens <[email protected]>
* @author Floris Kint <[email protected]>
*
* @license http://litus.cc/LICENSE
*/

namespace TicketBundle\Component\Validator;

/**
* Check the option is valid to use in a url
*
* @author Kristof Mariën <[email protected]>
*/
class UrlValid extends \CommonBundle\Component\Validator\AbstractValidator
{
const NOT_VALID = 'notValid';

/**
* Error messages
*
* @var array
*/
protected $messageTemplates = array(
self::NOT_VALID => 'The option can\'t contain the following characters: & + . #',
);

/**
* Sets validator options
*
* @param integer|array|\Traversable $options
*/
public function __construct($options = array())
{
parent::__construct($options);
}

/**
* Returns true if the format is right
*
* @param string $value The value of the field that will be validated
* @param array|null $context The context of the field that will be validated
* @return boolean
*/
public function isValid($value, $context = null)
{
$this->setValue($value);

if (!is_string($value)) {
return false;
}

if(str_contains($value,'&') or str_contains($value,'+') or str_contains($value,'.') or str_contains($value,'#'))

$this->error(self::NOT_VALID);

return false;
}
}
3 changes: 3 additions & 0 deletions module/TicketBundle/Form/Admin/Event/Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public function init()
'filters' => array(
array('name' => 'StringTrim'),
),
'validators' => array(
array('name' => 'UrlValid'),
),
),
),
)
Expand Down
1 change: 1 addition & 0 deletions module/TicketBundle/Resources/config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
'payid' => Component\Validator\PayId::class,
'payId' => Component\Validator\PayId::class,
'PayId' => Component\Validator\PayId::class,
'UrlValid' => Component\Validator\UrlValid::class,
),
),
)
Expand Down

0 comments on commit c1f3fa7

Please sign in to comment.