From 174c3fd6a9664a110627749cd9c1db953aa70d6e Mon Sep 17 00:00:00 2001 From: Mathieu Champlon Date: Wed, 8 Aug 2018 10:35:25 +0200 Subject: [PATCH] Fix invalid directory names --- manifest/index.go | 10 ++++++++++ templates/product.wxs | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/manifest/index.go b/manifest/index.go index 6335a8f..107a1ed 100644 --- a/manifest/index.go +++ b/manifest/index.go @@ -26,6 +26,7 @@ type WixManifest struct { Files WixFiles `json:"files,omitempty"` Directories []string `json:"directories,omitempty"` RelDirs []string `json:"-"` + DirNames []string `json:"-"` Env WixEnvList `json:"env,omitempty"` Shortcuts WixShortcuts `json:"shortcuts,omitempty"` Choco ChocoSpec `json:"choco,omitempty"` @@ -214,6 +215,7 @@ func (wixFile *WixManifest) RewriteFilePaths(out string) error { return err } wixFile.RelDirs = append(wixFile.RelDirs, r) + wixFile.DirNames = append(wixFile.DirNames, cleanDirectoryName(r)) } for i, s := range wixFile.Shortcuts.Items { if s.Icon != "" { @@ -230,6 +232,14 @@ func (wixFile *WixManifest) RewriteFilePaths(out string) error { return nil } +// cleanDirectoryName replaces invalid characters in directory names. +func cleanDirectoryName(name string) string { + to := "-" + repl := strings.NewReplacer( + `\`, to, "?", to, "|", to, ">", to, "<", to, ":", to, "/", to, "*", to, `"`, to) + return repl.Replace(name) +} + // Normalize Appropriately fixes some values within the decoded json // It applies defaults values on the wix/msi property to // to generate the msi package. diff --git a/templates/product.wxs b/templates/product.wxs index 072454b..5f3f84e 100644 --- a/templates/product.wxs +++ b/templates/product.wxs @@ -38,8 +38,8 @@ {{end}} {{end}} - {{if gt (.Directories | len) 0}} - {{range $i, $e := .Directories}} + {{if gt (.DirNames | len) 0}} + {{range $i, $e := .DirNames}} {{end}} {{end}}