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 9273063
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 @@ -25,6 +25,7 @@ type WixManifest struct {
UpgradeCode string `json:"upgrade-code"`
Files WixFiles `json:"files,omitempty"`
Directories []string `json:"directories,omitempty"`
DirNames []string `json:"-"`
RelDirs []string `json:"-"`
Env WixEnvList `json:"env,omitempty"`
Shortcuts WixShortcuts `json:"shortcuts,omitempty"`
Expand Down Expand Up @@ -205,6 +206,7 @@ func (wixFile *WixManifest) RewriteFilePaths(out string) error {
}
}
for _, d := range wixFile.Directories {
wixFile.DirNames = append(wixFile.DirNames, cleanDirectoryName(d))
d, err = filepath.Abs(d)
if err != nil {
return err
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 9273063

Please sign in to comment.