check extension names don't have spoaces

This commit is contained in:
Matt Joyce
2024-12-05 20:39:40 +11:00
parent 6fc75282e8
commit c49f47ecab
2 changed files with 11 additions and 6 deletions

View File

@@ -7,6 +7,7 @@ import (
"io"
"os"
"path/filepath"
"strings"
"time"
"gopkg.in/yaml.v3"
@@ -118,9 +119,13 @@ func (r *ExtensionRegistry) Register(configPath string) error {
return fmt.Errorf("failed to parse config file: %w", err)
}
// Add validation
if err := r.validateExtensionDefinition(&ext); err != nil {
return fmt.Errorf("invalid extension configuration: %w", err)
// Validate extension name
if ext.Name == "" {
return fmt.Errorf("extension name cannot be empty")
}
if strings.Contains(ext.Name, " ") {
return fmt.Errorf("extension name '%s' contains spaces - names must not contain spaces", ext.Name)
}
// Verify executable exists

View File

@@ -15,18 +15,18 @@ var (
fetchPlugin = &FetchPlugin{}
sysPlugin = &SysPlugin{}
extensionManager *ExtensionManager
Debug = true // Debug flag
Debug = false // Debug flag
)
func init() {
homedir, err := os.UserHomeDir()
if err != nil {
// We should probably handle this error appropriately
return
debugf("Warning: could not initialize extension manager: %v\n", err)
}
configDir := filepath.Join(homedir, ".config/fabric")
extensionManager = NewExtensionManager(configDir)
// Extensions will work if registry exists, otherwise they'll just fail gracefully
}
var pluginPattern = regexp.MustCompile(`\{\{plugin:([^:]+):([^:]+)(?::([^}]+))?\}\}`)