Skip to content

Commit

Permalink
Latte strict parsing mode (#246)
Browse files Browse the repository at this point in the history
Has to be enabled with `$latteEngine->setStrictParsing()` because when
enabled in new Linter with the strict param, it's only used when no
custom engine is passed.

Close #241
  • Loading branch information
spaze authored Oct 17, 2023
2 parents e6bd441 + b16b4d7 commit 046b5f6
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 35 deletions.
2 changes: 1 addition & 1 deletion site/app/Admin/Presenters/templates/Trainings/date.latte
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<td><small n:tag-if="$application->getName() === null"><a n:href="Trainings:application $application->getId()">{$application->getName() ?? smazáno}</a></small></td>
<td><small>{$application->getEmail() ?? smazáno}</small></td>
<td><span n:tag-if="$application->getCompany() && ($application->getCompany()|length) > 40" title="{$application->getCompany()}">{$application->getCompany()|truncate:40}</span></td>
<td><small{if $application->getNote() && ($application->getNote()|length) > 20} title="{$application->getNote()}"{/if}>{$application->getNote()|truncate:20}</small></td>
<td><small n:attr="title: $application->getNote() && ($application->getNote()|length) > 20 ? $application->getNote()">{$application->getNote()|truncate:20}</small></td>
<td><small><code title="{$application->getStatusTime()|localeDay} {$application->getStatusTime()|date:'H:i:s'}">{$application->getStatus()}</code></small></td>
<td><small>&raquo;</small></td>
<td>{input "applications-{$application->getId()}" class => status}</td>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
<pre>
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
eth0: flags=4163&lt;UP,BROADCAST,RUNNING,MULTICAST&gt; mtu 1500
inet 10.1.3.37 netmask 255.255.255.0 broadcast 10.1.3.255
inet6 fe80::e7f8:e51:dead:b33f prefixlen 64 scopeid 0x20<link>
inet6 fe80::e7f8:e51:dead:b33f prefixlen 64 scopeid 0x20&lt;link&gt;
ether e8:99:ca:fe:ba:be txqueuelen 1000 (Ethernet)
RX packets {$eth0RxPackets} bytes {$eth0RxBytes} (11.8 GB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets {$eth0TxPackets} bytes {$eth0TxBytes} (1.6 GB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 9001
eth1: flags=4163&lt;UP,BROADCAST,RUNNING,MULTICAST&gt; mtu 9001
inet 10.0.37.137 netmask 255.255.240.0 broadcast 10.0.37.255
inet6 32a6:caf0:d876:3666:cafe:d00d:d371:2d15 prefixlen 128 scopeid 0x0<global>
inet6 fe80::518:bad:f00d:1af2 prefixlen 64 scopeid 0x20<link>
inet6 32a6:caf0:d876:3666:cafe:d00d:d371:2d15 prefixlen 128 scopeid 0x0&lt;global&gt;
inet6 fe80::518:bad:f00d:1af2 prefixlen 64 scopeid 0x20&lt;link&gt;
ether 4a:e0:fa:57:f0:0d txqueuelen 1000 (Ethernet)
RX packets {$eth1RxPackets} bytes {$eth1RxBytes} (231.8 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets {$eth1TxPackets} bytes {$eth1TxBytes} (372.1 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
lo: flags=73&lt;UP,LOOPBACK,RUNNING&gt; mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
inet6 ::1 prefixlen 128 scopeid 0x10&lt;host&gt;
loop txqueuelen 1000 (Local Loopback)
RX packets {$loRxPackets} bytes {$loRxBytes} (2.5 MB)
RX errors 0 dropped 0 overruns 0 frame 0
Expand Down
50 changes: 28 additions & 22 deletions site/app/Pulse/Presenters/templates/PasswordsStorages/default.latte
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,26 @@
<meta name="twitter:site" content="@spazef0rze">
{/define}

{define #algoItem, MichalSpacekCz\Pulse\Passwords\Storage $storage, MichalSpacekCz\Pulse\Passwords\Algorithm $algo, string $detailsLink, string $detailsParam, ?string $noFollow}
<div class="algo">
<strong n:class="$storage->getSearchResult()->isAlgorithmNameMatch($algo) ? search-result">{$algo->getName()}</strong> (<span n:if="$algo->getFrom() && $algo->isFromConfirmed()" title="{$algo->getFrom()|date:'Y-m'}">since {$algo->getFrom()|date:'F Y'}</span>{if $algo->getFrom() && $algo->isFromConfirmed()}, {/if}<span title="{$algo->getLatestDisclosure()->getPublished()|date:'Y-m-d'}">disclosed {$algo->getLatestDisclosure()->getPublished()|date:'F Y'}</span>)
</div>
<div class="details">
{if $algo->getDisclosures()}
<div><a n:href="$detailsLink $detailsParam" n:class="open-button, $isDetail ? open, $storage->getSearchResult()->isAlgorithmDisclosureUrlMatch($algo) ? search-result">Details</a></div>
<div n:class="expandable, !$isDetail ? hidden">
<p n:if="$algo->getNote()">Note: {$algo->getNote()|format}</p>
<p n:if="$algo->getParams()">Params: {foreach $algo->getParams() as $key => $value}<code>{$key}={$value}</code>{sep}, {/sep}{/foreach}</p>
<p n:if="$algo->getFullAlgo()">Full algorithm: <code>{$algo->getFullAlgo()}</code></p>
<p>Disclosures:</p>
<ul n:inner-foreach="$algo->getDisclosures() as $disclosure">
<li><small title="{$disclosure->getPublished()|date:'Y-m-d H:i'}">{$disclosure->getPublished()|date:'Y-m-d'}</small> <a href="{$disclosure->getUrl()}" n:attr="rel => $noFollow" n:class="$storage->getSearchResult()->isDisclosureUrlMatch($disclosure) ? search-result">{$disclosure->getType()}</a>{if $disclosure->getArchive()} <sup><a href="{$disclosure->getArchive()}" title="archived">arch</a></sup>{/if}{if $disclosure->getNote()}<small> ({$disclosure->getNote()|format})</small>{/if}</li>
</ul>
</div>
{/if}
</div>
{/define}

{define #content}
<div n:if="!$isDetail" id="search-sort" n:class="inner-container, !$openSearchSort ? hidden">
<form n:name="searchSort">
Expand All @@ -39,7 +59,7 @@
<h2 id="{$data->getCompany($storage->getCompanyId())->getCompanyAlias()}" n:if="!$data->getCompany($storage->getCompanyId())->getTradeName()"><span n:tag-if="$storage->getSearchResult()->isCompanyNameMatch($data->getCompany($storage->getCompanyId()))" class="search-result">{$data->getCompany($storage->getCompanyId())->getCompanyName()}</span></h2>
<h2 id="{$data->getCompany($storage->getCompanyId())->getCompanyAlias()}" n:if="$data->getCompany($storage->getCompanyId())->getTradeName()"><span n:tag-if="$storage->getSearchResult()->isCompanyNameMatch($data->getCompany($storage->getCompanyId()))">{$data->getCompany($storage->getCompanyId())->getTradeName()}</span> <small>(<span n:tag-if="$storage->getSearchResult()->isCompanyNameMatch($data->getCompany($storage->getCompanyId()))" class="search-result">{$data->getCompany($storage->getCompanyId())->getCompanyName()}</span>)</small></h2>
{foreach $storage->getSites() as $site}
{var $noFollow = ($site->isSecureStorage() ? false : 'nofollow')}
{var $noFollow = ($site->isSecureStorage() ? null : 'nofollow')}
{if $site instanceof \MichalSpacekCz\Pulse\SpecificSite}
{var $detailsLink = 'site'}
{var $detailsParam = $site->getAlias()}
Expand Down Expand Up @@ -70,27 +90,13 @@
<div class="clear"></div>
</div>
<div class="algo-container">
{foreach $site->getAlgorithms() as $algo}
{if $iterator->counter === 2}<div><div><a n:href="$detailsLink $detailsParam" n:class="open-button, $isDetail ? open, $storage->getSearchResult()->isDisclosureHistoryMatch() ? search-result">History</a></div><div n:class="history, expandable, !$isDetail ? hidden">{/if}
<div class="algo">
<strong n:class="$storage->getSearchResult()->isAlgorithmNameMatch($algo) ? search-result">{$algo->getName()}</strong> (<span n:if="$algo->getFrom() && $algo->isFromConfirmed()" title="{$algo->getFrom()|date:'Y-m'}">since {$algo->getFrom()|date:'F Y'}</span>{if $algo->getFrom() && $algo->isFromConfirmed()}, {/if}<span title="{$algo->getLatestDisclosure()->getPublished()|date:'Y-m-d'}">disclosed {$algo->getLatestDisclosure()->getPublished()|date:'F Y'}</span>)
</div>
<div class="details">
{if $algo->getDisclosures()}
<div><a n:href="$detailsLink $detailsParam" n:class="open-button, $isDetail ? open, $storage->getSearchResult()->isAlgorithmDisclosureUrlMatch($algo) ? search-result">Details</a></div>
<div n:class="expandable, !$isDetail ? hidden">
<p n:if="$algo->getNote()">Note: {$algo->getNote()|format}</p>
<p n:if="$algo->getParams()">Params: {foreach $algo->getParams() as $key => $value}<code>{$key}={$value}</code>{sep}, {/sep}{/foreach}</p>
<p n:if="$algo->getFullAlgo()">Full algorithm: <code>{$algo->getFullAlgo()}</code></p>
<p>Disclosures:</p>
<ul n:inner-foreach="$algo->getDisclosures() as $disclosure">
<li><small title="{$disclosure->getPublished()|date:'Y-m-d H:i'}">{$disclosure->getPublished()|date:'Y-m-d'}</small> <a href="{$disclosure->getUrl()}" n:attr="rel => $noFollow" n:class="$storage->getSearchResult()->isDisclosureUrlMatch($disclosure) ? search-result">{$disclosure->getType()}</a>{if $disclosure->getArchive()} <sup><a href="{$disclosure->getArchive()}" title="archived">arch</a></sup>{/if}{if $disclosure->getNote()}<small> ({$disclosure->getNote()|format})</small>{/if}</li>
</ul>
</div>
{/if}
</div>
{if $iterator->count() > 1 && $iterator->last}</div></div>{/if}
{/foreach}
{include #algoItem, storage: $storage, algo: $site->getLatestAlgorithm(), detailsLink: $detailsLink, detailsParam: $detailsParam, noFollow: $noFollow}
<div n:if="$site->getHistoricalAlgorithms()">
<div><a n:href="$detailsLink $detailsParam" n:class="open-button, $isDetail ? open, $storage->getSearchResult()->isDisclosureHistoryMatch() ? search-result">History</a></div>
<div n:class="history, expandable, !$isDetail ? hidden" n:foreach="$site->getHistoricalAlgorithms() as $algo">
{include #algoItem, storage: $storage, algo: $algo, detailsLink: $detailsLink, detailsParam: $detailsParam, noFollow: $noFollow}
</div>
</div>
<div>
<div><a n:href="$detailsLink $detailsParam" n:class="open-button, $isDetail ? open">Why &quot;{$site->getRating()->name}&quot;?</a></div>
<div n:class="expandable, !$isDetail ? hidden">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<ol><li n:foreach="$invisibleDisclosures as $disclosure">{$disclosure}</li></ol>
<h3>Accounts</h3>
<p><em>Official account</em> is a company or site account, with official information.</p>
<p><em>Private account</em> is run by someone who is, or was, working for a company or a site, not official information.
<p><em>Private account</em> is run by someone who is, or was, working for a company or a site, not official information.</p>
<p><em>Independent account</em> is an account run by someone not affiliated with a company or a site in any way.</p>
</div>
{/define}
6 changes: 6 additions & 0 deletions site/app/Pulse/Site.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ public function addAlgorithm(Algorithm $algorithm): void;
public function getLatestAlgorithm(): Algorithm;


/**
* @return array<string, Algorithm>
*/
public function getHistoricalAlgorithms(): array;


public function getRating(): RatingGrade;


Expand Down
9 changes: 9 additions & 0 deletions site/app/Pulse/WildcardSite.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ public function getLatestAlgorithm(): Algorithm
}


/**
* @return array<string, Algorithm>
*/
public function getHistoricalAlgorithms(): array
{
return array_slice($this->algorithms, 1);
}


public function getRating(): RatingGrade
{
if (!$this->ratingGrade) {
Expand Down
3 changes: 2 additions & 1 deletion site/app/Training/DateList/trainingApplicationsList.latte
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<td><small n:tag-if="$application->getName() === null"><a href="{plink Trainings:application $application->getId()}">{$application->getName() ?? smazáno}</a></small></td>
<td><small>{$application->getEmail() ?? smazáno}</small></td>
<td><span n:tag-if="$application->getCompany() && ($application->getCompany()|length) > 40" title="{$application->getCompany()}">{$application->getCompany()|truncate:40}</span></td>
<td><small{if $application->getNote() && ($application->getNote()|length) > 20} title="{$application->getNote()}"{/if}>{$application->getNote()|truncate:20}</small></td>
<td><small n:attr="title: $application->getNote() && ($application->getNote()|length) > 20 ? $application->getNote()">{$application->getNote()|truncate:20}</small></td>
<td><small><code title="{$application->getStatusTime()|localeDay} {$application->getStatusTime()|date:'H:i:s'}">{$application->getStatus()}</code></small></td>
<td>
<small><code title="Zdroj {$application->getSourceName()}">{$application->getSourceNameInitials()}</code></small>
Expand Down Expand Up @@ -81,6 +81,7 @@
<th><small>Poznámka</small></th>
<th><small>Status</small></th>
<th><small title="Cena bez DPH">Cena</small></th>
</tr>
</thead>
<tbody n:if="$training->getApplications()">{include #listItems, applications: $training->getApplications()}</tbody>
<tbody n:if="$training->getCanceledApplications()" class="discarded">{include #listItems, applications: $training->getCanceledApplications()}</tbody>
Expand Down
1 change: 0 additions & 1 deletion site/app/Www/Presenters/templates/Trainings/reviews.latte
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
{include "common/itemReview.latte", review: $review}
{/foreach}
</div>
<p>
<p>
{capture $link}Www:Trainings:training#{_html.id.application}{/capture}
{_messages.trainings.jointhem|format:"link:$link $name", $title, "link:Www:Trainings:training $name"}<br>
Expand Down
13 changes: 11 additions & 2 deletions site/bin/latte-lint.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,21 @@
echo 'Custom filters: ' . ($customFilters ? implode(', ', $customFilters) : 'none installed') . "\n";

if ($argc < 2) {
echo "Usage: latte-lint <path>\n";
echo "Usage: latte-lint <path> [--debug] [--disable-strict-parsing]\n";
exit(1);
}

$debug = in_array('--debug', $argv, true);
if ($debug) {
echo "Debug mode enabled\n";
}
$strictParsing = !in_array('--disable-strict-parsing', $argv, true);
if ($strictParsing) {
echo "Strict parsing mode enabled\n";
}
$path = $argv[1];
$linter = new Linter($factory->createTemplate()->getLatte(), $debug);
$latteEngine = $factory->createTemplate()->getLatte();
$latteEngine->setStrictParsing($strictParsing);
$linter = new Linter($latteEngine, $debug);
$ok = $linter->scanDirectory($path);
exit($ok ? 0 : 1);
1 change: 1 addition & 0 deletions site/config/common.neon
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ di:
tags: false

latte:
strictParsing: true
strictTypes: true

database:
Expand Down
3 changes: 3 additions & 0 deletions site/tests/Pulse/Passwords/PasswordsTest.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ class PasswordsTest extends TestCase
Assert::count(2, $disclosures);
Assert::same(2, $disclosures[0]->getId());
Assert::same(3, $disclosures[1]->getId());
Assert::same([$bcryptKey, $sha1Key], array_keys($site->getHistoricalAlgorithms()));
}

$site = $storageRegistry->getSite('111');
Expand All @@ -318,6 +319,7 @@ class PasswordsTest extends TestCase
Assert::null($latestAlgorithm->getFullAlgo());
Assert::same('bcrypt', $latestAlgorithm->getName());
Assert::same(158, $latestAlgorithm->getLatestDisclosure()->getId());
Assert::same([], array_keys($site->getHistoricalAlgorithms()));
}

$company = $storageRegistry->getCompany(3);
Expand All @@ -340,6 +342,7 @@ class PasswordsTest extends TestCase
$disclosures = $site->getAlgorithms()[$sha256Key]->getDisclosures();
Assert::count(1, $disclosures);
Assert::same(6, $site->getAlgorithms()[$sha256Key]->getDisclosures()[0]->getId());
Assert::same([$sha256Key], array_keys($site->getHistoricalAlgorithms()));
}
}

Expand Down

0 comments on commit 046b5f6

Please sign in to comment.