feat: .env-Varianten und Kopien mit Zusatzendung im Editor

.env, .env.local, .env.production, app.env usw. gelten immer als Text.
Zusatzendungen wie .example, .sample, .dist, .bak, .orig, .local werden
bei der Typerkennung abgeschnitten (nginx.conf.sample, config.yml.dist).
Gleiche Regeln in preview.php und app.js. Paket 2026.11.21.r007.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Mikei386andClaude Opus 5.5 committed 2026-11-21 13:46:56 +01:00
1 parent 1ca0d5aaae
commit 0117670ede
7 files changed
+46 -5

No files matched your search

@@ -3,6 +3,12 @@ require_once __DIR__ . '/common.php';
const UNAV_TEXT_PREVIEW_MAX_BYTES = 1048576;
// Copies and variants keep the type of the real file: ".env.local", "nginx.conf.sample",
// "config.yml.dist", "settings.json.bak" … are matched without their trailing suffix.
const UNAV_VARIANT_SUFFIXES = ['example', 'sample', 'dist', 'template', 'default', 'defaults', 'local', 'bak', 'backup',
'orig', 'old', 'new', 'save', 'saved', 'tmp', 'disabled', 'off', 'prev', 'last', 'production', 'prod', 'staging',
'development', 'dev', 'test', 'testing', 'ci'];
$resolved = unav_existing_path($_GET['path'] ?? null);
unav_assert_not_pseudo_fs($resolved['path']);
if (!is_file($resolved['path'])) {
@@ -160,6 +166,20 @@ function unav_write_all($handle, string $content): bool {
}
function unav_preview_type(string $extension, string $name): ?string {
$lower = strtolower($name);
// .env, .env.local, .env.production, app.env …
if (preg_match('/(^\.?env($|\.))|(\.env($|\.))/', $lower)) {
return 'text';
}
$type = unav_preview_type_exact($extension, $name);
while ($type === null && preg_match('/^(.+)\.([a-z0-9_-]+)$/', $lower, $match) && in_array($match[2], UNAV_VARIANT_SUFFIXES, true)) {
$lower = $match[1];
$type = unav_preview_type_exact(strtolower(pathinfo($lower, PATHINFO_EXTENSION)), $lower);
}
return $type;
}
function unav_preview_type_exact(string $extension, string $name): ?string {
$base = strtolower($name);
$textNames = ['dockerfile', 'containerfile', 'makefile', 'gnumakefile', 'vagrantfile', 'gemfile', 'rakefile', 'procfile',
'jenkinsfile', 'caddyfile', 'brewfile', 'go', 'hosts', 'fstab', 'crontab', 'exports', 'passwd', 'group', 'shells',