Skip to content

Commit

Permalink
[+]: "Tweak regex" | thanks @WillGibson
Browse files Browse the repository at this point in the history
  • Loading branch information
voku committed Jun 24, 2017
1 parent c3e9f51 commit 93c30f9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
15 changes: 8 additions & 7 deletions src/voku/helper/URLify.php
Original file line number Diff line number Diff line change
Expand Up @@ -1627,12 +1627,12 @@ class URLify
/**
* Add new strings the will be replaced with the separator.
*
* @param array $array
* @param bool $replace
* @param array $array <p>An array of things that should replaced by the separator.</p>
* @param bool $merge <p>Keep the previous (default) array-to-separator array.</p>
*/
public static function add_array_to_separator(array $array, $replace = false)
public static function add_array_to_separator(array $array, $merge = true)
{
if ($replace === false) {
if ($merge === true) {
self::$arrayToSeparator = array_merge(self::$arrayToSeparator, $array);
} else {
self::$arrayToSeparator = $array;
Expand Down Expand Up @@ -1666,16 +1666,17 @@ public static function add_chars(array $map)
/**
* Append words to the remove list. Accepts either single words or an array of words.
*
* @param mixed $words
* @param string $language
* @param boolean $merge <p>Keep the previous (default) remove-words-array</p>
* @param string|string[] $words
* @param string $language
* @param boolean $merge <p>Keep the previous (default) remove-words array.</p>
*/
public static function remove_words($words, $language = 'de', $merge = true)
{
if (is_array($words) === false) {
$words = array($words);
}

/** @noinspection ForeachSourceInspection */
foreach ($words as $removeWordKey => $removeWord) {
$words[$removeWordKey] = preg_quote($removeWord, '/');
}
Expand Down
4 changes: 2 additions & 2 deletions tests/URLifyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,14 @@ public function testAddArrayToSeparator()
self::assertSame('14-14-34-P-abc', URLify::filter('? ¿ >-< &amp; ® ¼ ¼ ¾ ¶ <br> ; ! abc'));
URLify::reset_array_to_separator();

// replace
// merge

URLify::add_array_to_separator(
array(
'/®/',
'/tester/',
),
true
false
);
self::assertSame('und-amp-14-14-34-P-abc', URLify::filter('? ¿ >-< &amp; ® ¼ ¼ ¾ ¶ <br> ; ! abc'));
URLify::reset_array_to_separator();
Expand Down

0 comments on commit 93c30f9

Please sign in to comment.