Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Bridge/Symfony/CocurSlugifyExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function load(array $configs, ContainerBuilder $container)
}

// Extract slugify arguments from config
$slugifyArguments = array_intersect_key($config, array_flip(['lowercase', 'separator', 'regexp', 'rulesets']));
$slugifyArguments = array_intersect_key($config, array_flip(['lowercase', 'trim', 'strip_tags', 'separator', 'regexp', 'rulesets']));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

trim was missing here.


$container->setDefinition('cocur_slugify', new Definition('Cocur\Slugify\Slugify', [$slugifyArguments]));
$container
Expand Down
1 change: 1 addition & 0 deletions src/Bridge/Symfony/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function getConfigTreeBuilder()
->children()
->booleanNode('lowercase')->end()
->booleanNode('trim')->end()
->booleanNode('strip_tags')->end()
->scalarNode('separator')->end()
->scalarNode('regexp')->end()
->arrayNode('rulesets')->prototype('scalar')->end()
Expand Down
5 changes: 5 additions & 0 deletions src/Slugify.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class Slugify implements SlugifyInterface
'separator' => '-',
'lowercase' => true,
'trim' => true,
'strip_tags' => false,
'rulesets' => [
'default',
// Languages are preferred if they appear later, list is ordered by number of
Expand Down Expand Up @@ -111,6 +112,10 @@ public function slugify($string, $options = null)
$rules = $this->rules;
}

$string = ($options['strip_tags'])
? strip_tags($string)
: $string;

$string = strtr($string, $rules);
unset($rules);

Expand Down
10 changes: 10 additions & 0 deletions tests/Bridge/Symfony/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public function testAll()
$configs = [
[
'lowercase' => true,
'strip_tags' => false,
'separator' => '_',
'regexp' => 'abcd',
'rulesets' => ['burmese', 'hindi']
Expand All @@ -39,6 +40,15 @@ public function testLowercaseOnlyAcceptsBoolean()
$this->process($configs);
}

/**
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidTypeException
*/
public function testStripTagsOnlyAcceptsBoolean()
{
$configs = [['strip_tags' => 'abc']];
$this->process($configs);
}

/**
* Processes an array of configurations and returns a compiled version.
*
Expand Down
4 changes: 4 additions & 0 deletions tests/SlugifyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ public function slugifyOptionsArray()

$this->assertEquals('file-name', $this->slugify->slugify('file name '));
$this->assertEquals('file-name-', $this->slugify->slugify('file name ', ['trim' => false]));

$this->assertEquals('file-name', $this->slugify->slugify('<file name'));
$this->assertEquals('p-file-p-foo-a-href-bar-name-a', $this->slugify->slugify('<p>file</p><!-- foo --> <a href="#bar">name</a>'));
$this->assertEquals('file-name', $this->slugify->slugify('<p>file</p><!-- foo --> <a href="#bar">name</a>', ['strip_tags' => true]));
}

/**
Expand Down