Skip to content

Commit

Permalink
Alter regex to match different icon styles (resolve #7)
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrian Perez committed Sep 25, 2019
1 parent 2aa7f33 commit b88560f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class filter_fontawesome extends moodle_text_filter {
public function filter($text, array $options = array()) {

// We should search only for reference to FontAwesome icons and if optional icon and fab classes are set.
$search = "(\[((?:icon\s)?)((?:fab\s)?)(fa-[a-z0-9 -]+)\])is";
$search = "(\[((?:icon\s)?)((?:fa[a-z]\s)?)(fa-[a-z0-9 -]+)\])is";
$result = preg_replace_callback($search, array($this, 'filter_fontawesome_callback'), $text);

return $result;
Expand Down
5 changes: 5 additions & 0 deletions tests/filter_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ public function test_cases() {
$this->run_with_content('icon fa-check fa-4x', true);
$this->run_with_content('fab fa-telegram', true);
$this->run_with_content('fab fa-telegram fa-5x', true);
$this->run_with_content('fad fa-angel', true);
$this->run_with_content('fal fa-child fa-2x', true);
$this->run_with_content('fas fa-smile', true);
$this->run_with_content('far fa-book', true);
// Now test some cases that shouldn't be executed.
$this->run_with_content('Some text fa-check', false);
$this->run_with_content('fas-check', false);
Expand All @@ -89,5 +93,6 @@ public function test_cases() {
$this->run_with_content('f-check', false);
$this->run_with_content('fa-check onmouseover="alert(1)"', false);
$this->run_with_content('fa-check" onmouseover="alert(1)""', false);
$this->run_with_content('fad-angel', false);
}
}

0 comments on commit b88560f

Please sign in to comment.