Skip to content

Commit 96a0b43

Browse files
committed
Allow mixed cases for icon and linkmod class matchers
1 parent 5b86a39 commit 96a0b43

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
- More accurate regex matching of icon and linkmod classnames.
55
- Changed composer package type to `library` from `wordpress-plugin` again.
66
- Tests: Add unit tests for the function that separates classnames for the walker.
7+
- Fix case sensitive matching to now match mixes of upper and lower case.
78

89
## [4.0.1]
910
- Fix untranslated string in fallback (this was lost in transition between v3 and v4, fixed again).

class-wp-bootstrap-navwalker.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -403,20 +403,20 @@ private function seporate_linkmods_and_icons_from_classes( $classes, &$linkmod_c
403403
foreach ( $classes as $key => $class ) {
404404
// If any special classes are found, store the class in it's
405405
// holder array and and unset the item from $classes.
406-
if ( preg_match( '/^disabled|^sr-only/', $class ) ) {
406+
if ( preg_match( '/^disabled|^sr-only/i', $class ) ) {
407407
// Test for .disabled or .sr-only classes.
408408
$linkmod_classes[] = $class;
409409
unset( $classes[ $key ] );
410-
} elseif ( preg_match( '/^dropdown-header|^dropdown-divider/', $class ) && $depth > 0 ) {
410+
} elseif ( preg_match( '/^dropdown-header|^dropdown-divider/i', $class ) && $depth > 0 ) {
411411
// Test for .dropdown-header or .dropdown-divider and a
412412
// depth greater than 0 - IE inside a dropdown.
413413
$linkmod_classes[] = $class;
414414
unset( $classes[ $key ] );
415-
} elseif ( preg_match( '/^fa-(\S*)?|^fa(s|r|l|b)?(\s?)?$/', $class ) ) {
415+
} elseif ( preg_match( '/^fa-(\S*)?|^fa(s|r|l|b)?(\s?)?$/i', $class ) ) {
416416
// Font Awesome.
417417
$icon_classes[] = $class;
418418
unset( $classes[ $key ] );
419-
} elseif ( preg_match( '/^glyphicon-(\S*)?|^glyphicon(\s?)$/', $class ) ) {
419+
} elseif ( preg_match( '/^glyphicon-(\S*)?|^glyphicon(\s?)$/i', $class ) ) {
420420
// Glyphicons.
421421
$icon_classes[] = $class;
422422
unset( $classes[ $key ] );

tests/test-navwalker.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ function setUp() {
4646
'sr-only',
4747
) );
4848

49-
// array of valid font-awesome icon class starters plus some randomly chosen icon classes.
49+
// array of valid font-awesome icon class starters plus some randomly
50+
// chosen icon classes and some variations of upper/lower case letters.
5051
$this->some_fontawesome_classes = array(
5152
'fa',
5253
'fas',
@@ -58,9 +59,13 @@ function setUp() {
5859
'fa-home',
5960
'fa-bluetooth-b',
6061
'fa-chess-rook',
62+
'fA-home',
63+
'Fa-HoMe',
64+
'fa-HomE',
6165
);
6266

63-
// array of valid glyphicon icon class starters plus some randomly chosen icon classes.
67+
// array of valid glyphicon icon class starters plus some randomly
68+
// chosen icon classes and some variations of upper/lower case letters.
6469
$this->some_glyphicons_classes = array(
6570
'glyphicon',
6671
'glyphicon-asterisk',
@@ -70,6 +75,10 @@ function setUp() {
7075
'glyphicon-sd-video',
7176
'glyphicon-subscript',
7277
'glyphicon-grain',
78+
'Glyphicon-file',
79+
'Glyphicon-File',
80+
'glyphicon-File',
81+
'glYphiCon-fiLe',
7382
);
7483

7584
}

0 commit comments

Comments
 (0)