Skip to content

Commit

Permalink
Double file extension policy - filtering js.gz
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Clifford committed Nov 27, 2020
1 parent b7a5908 commit 86080e4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
3 changes: 2 additions & 1 deletion Policies/double_file_extensions.policy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ parameters:
default: "%root/sites"
exclude:
default:
- sites/default/files/js
- "sites/default/files/js"
- "sites/default/files/js/optimized"
filetypes:
default:
- php
Expand Down
11 changes: 6 additions & 5 deletions src/Audit/DoubleFileExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ public function audit(Sandbox $sandbox) {
}

$matches = array_filter(explode(PHP_EOL, $output));

$matches = array_map(function ($line) {
list($filepath, $date) = explode(' ', $line);
return [
Expand All @@ -87,6 +86,10 @@ public function audit(Sandbox $sandbox) {
];
}, $matches);

$matches = array_filter($matches, function($line) {
return !strpos($line['basename'], 'js.gz') !== false;
});

$results = [
'found' => count($matches),
'findings' => $matches,
Expand All @@ -95,17 +98,15 @@ public function audit(Sandbox $sandbox) {
}, $matches)))
];


//TODO: Add a condiational check for Markdown format
//TODO: Add a conditional check for Markdown format
$columns = ['Basename', 'Date', 'Filename'];
$rows = [];
foreach ($results['findings'] as $key => $file) {
$rows[] = [$file['basename'], $file["date"], $file["file"]];
}

$md_table = new MarkdownTableGenerator($columns, $rows);

$results['findings'][] = ['markdown_display' => $md_table->render()];
$results['findings'] = ['markdown_display' => $md_table->render()];

$sandbox->setParameter('results', $results);

Expand Down

0 comments on commit 86080e4

Please sign in to comment.