Skip to content

Commit

Permalink
Merge branch 'trunk' into add-changelog-v1.2.6
Browse files Browse the repository at this point in the history
  • Loading branch information
gudmdharalds authored Aug 8, 2022
2 parents 084ac7b + e869b00 commit dbebd60
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 2 deletions.
42 changes: 40 additions & 2 deletions misc.php
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,9 @@ function vipgoci_file_extension_get(

/**
* Determine if the presented file has an
* allowable file-ending, and if the file presented
* is in a directory that is can be scanned.
* allowable file-ending, if the file presented
* is in a directory that can be skipped or included
* for scanning.
*
* @param string $filename File name; is expected to be a relative path to the git-repository root.
* @param null|array $filter Filter to apply.
Expand Down Expand Up @@ -433,6 +434,43 @@ function vipgoci_filter_file_path(
break;
}
}
} elseif (
( null !== $filter ) &&
( isset( $filter['include_folders'] ) )
) {
/*
* Loop through all include-folders specified.
*/
foreach (
$filter['include_folders'] as $tmp_include_folder_item
) {
/*
* Note: All 'include_folders' options should lack '/' at the
* end and beginning.
*
* $filename we expect to be a relative path.
*/
$file_folders_match = strpos(
$filename,
$tmp_include_folder_item . '/'
);

/*
* If it's not a match, then that folder is to be skipped.
*
* There can only be 1 match with the filename so the
* moment that happens, we break out.
*/
if (
( false !== $file_folders_match ) &&
( is_numeric( $file_folders_match ) )
) {
$file_folders_match = false;
break;
} else {
$file_folders_match = true;
}
}
}

/*
Expand Down
94 changes: 94 additions & 0 deletions tests/unit/MiscFilterFilePathTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,100 @@ public function testFilterFilePath5() {

}

/**
* @covers ::vipgoci_filter_file_path
*/
public function testFilterFilePath6() {
$file_name = 'folder1/file1.txt';

$this->assertFalse(
vipgoci_filter_file_path(
$file_name,
array(
'include_folders' => array(
'folder2',
)
)
)
);

$this->assertTrue(
vipgoci_filter_file_path(
$file_name,
array(
'include_folders' => array(
'folder1',
)
)
)
);
}

/**
* @covers ::vipgoci_filter_file_path
*/
public function testFilterFilePath7() {
$file_name = 'my/unit-tests/folder1/subfolder/file1.txt';

$this->assertFalse(
vipgoci_filter_file_path(
$file_name,
array(
'include_folders' => array(
'folder200',
'folder3000',
'folder4000/folder5000/folder6000',
'SubFolder' // Note: capital 'F'
),
)
)
);

$this->assertTrue(
vipgoci_filter_file_path(
$file_name,
array(
'include_folders' => array(
'unit-tests/folder1/subfolder', // Note: Unlike skip_folders, this is allowed when it's not at root level
),
)
)
);

$this->assertTrue(
vipgoci_filter_file_path(
$file_name,
array(
'include_folders' => array(
'somefoldertesting/otherfolder/foobar123',
'somefoldertesting/otherfolder/foobar321',
'my/unit-tests/folder1/subfolder',
),
)
)
);

$this->assertTrue(
vipgoci_filter_file_path(
$file_name,
array(
'include_folders' => array(
'my/unit-tests',
),
)
)
);

$this->assertFalse(
vipgoci_filter_file_path(
$file_name,
array(
'include_folders' => array(
'test',
),
)
)
);

}
}

0 comments on commit dbebd60

Please sign in to comment.