Skip to content

Commit

Permalink
Fix invalid directory names
Browse files Browse the repository at this point in the history
  • Loading branch information
mat007 committed Aug 8, 2018
1 parent 7f05345 commit 174c3fd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 10 additions & 0 deletions manifest/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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 != "" {
Expand All @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions templates/product.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
{{end}}
</Component>
{{end}}
{{if gt (.Directories | len) 0}}
{{range $i, $e := .Directories}}
{{if gt (.DirNames | len) 0}}
{{range $i, $e := .DirNames}}
<Directory Id="APPDIR{{$i}}" Name="{{$e}}" />
{{end}}
{{end}}
Expand Down

0 comments on commit 174c3fd

Please sign in to comment.