From d8eb1cd17fa6a1ca4250387ce4c777aaf028d8a7 Mon Sep 17 00:00:00 2001 From: uroboro Date: Mon, 29 Aug 2022 23:24:34 +0200 Subject: [PATCH] [Fix 72] generator config is not case-sensitive consistent Perl's `can_load` is case-insensitive which means that the system can find case variations of generator names but `Thunk` later cannot properly load the module. For now, it detects the typo on the generator name but only warns the user instead of assuming which one they intended, to prevent allowing variations of the names to be used in source code. --- bin/lib/Logos/Generator.pm | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/bin/lib/Logos/Generator.pm b/bin/lib/Logos/Generator.pm index 0b11058..8b1ca03 100644 --- a/bin/lib/Logos/Generator.pm +++ b/bin/lib/Logos/Generator.pm @@ -1,7 +1,9 @@ package Logos::Generator; use strict; +use File::Basename; use Logos::Generator::Thunk; use Scalar::Util qw(blessed); +use List::Util qw(any); use Module::Load::Conditional qw(can_load); $Module::Load::Conditional::VERBOSE = 1; our $GeneratorPackage = ""; @@ -40,9 +42,20 @@ sub use { unshift @INC, $2; } $GeneratorPackage = "Logos::Generator::".$generatorName; - ::fileError(-1, "I can't find the $generatorName Generator!") if(!can_load(modules => { - $GeneratorPackage."::Generator" => undef - })); + ::fileError(-1, "I can't find the '$generatorName' Generator!") if (!can_load(modules => { + $GeneratorPackage . "::Generator" => undef + })); + + # Guard against case insensitive filesystems finding the module but not being able to load it + my @availableGeneratorPaths = glob(dirname(__FILE__) . "/Generator/*"); + my @availableGenerators = map {basename($_)} @availableGeneratorPaths; + my $generatorDirectoryExists = any {$_ eq $generatorName} @availableGenerators; + + if ($generatorDirectoryExists != 1) { + my %generatorNames = map {lc($_) => $_} @availableGenerators; + my $possibleGeneratorName = $generatorNames{lc($generatorName)}; + ::fileError(-1, "I can't find the '$generatorName' Generator, did you mean '$possibleGeneratorName'?"); + } } 1;