ncruces / zenity

Zenity dialogs for Golang, Windows, macOS
https://pkg.go.dev/github.com/ncruces/zenity
MIT License
736 stars 37 forks source link

Defect in initFilters #55

Closed peti634 closed 1 year ago

peti634 commented 1 year ago

Hi.

I use this repo for my project with VS Code IDE on Linux. When I add a Pattern to SelectFile dialog, its not appearing, just drop a error: dialog canceled

I have found the issue, in the initFilters function add an extra character to the end of string.

I added a fix - avoid a new space char to end - and everything is okay:

        for i, p := range f.Patterns {
            buf.WriteString(p)
            if i < len(f.Patterns)-1 {
                buf.WriteRune(' ')
            }
        }

(You can't reproduce the issue, if run it with "go run" or "go build", just when debugging, I don't know why)

Bye

ncruces commented 1 year ago

Hi.

I didn't quite get how to reproduce the bug, can you explain further?

peti634 commented 1 year ago

Yes, of course, here is the short example:

package main

import (
    "fmt"
    "os"

    "github.com/ncruces/zenity"
)

func main() {
    currentDir, _ := os.Getwd()
    saveFilePath, err := zenity.SelectFileSave(
        zenity.ConfirmOverwrite(),
        zenity.Filename(currentDir+"/map/"),
        zenity.FileFilters{{Name: "Map data file (*.txt)", Patterns: []string{"*.txt"}, CaseFold: false}})

    fmt.Print(saveFilePath, err)
}

I test it just now, and the issue is same (without my fix).

Other information that could help: go version go1.19 linux/amd64 Linux 5.15.0-69-generic Ubuntu 20.04 VS Code: 1.77.2

ncruces commented 1 year ago

I couldn't repro, but the fix seems harmless anyway.

peti634 commented 1 year ago

If call like this: exec.Command("zenity", "--file-selection", "--file-filter=Map data file (.txt)|.txt ") (so there is extra char at the end!!) There is nothing happen, so return a error!

But If I call this: exec.Command("zenity", "--file-selection", "--file-filter=Map data file (.txt)|.txt") Without extra char, then works!

Is it different on your side? :o

My zenity version: 3.32.0, so it is the latest

ncruces commented 1 year ago

Yes, no error. My zenity version is 3.43.0 (the latest on my package manager), maybe that's the difference.

peti634 commented 1 year ago

Indeed, thank you!

Bye

ncruces commented 1 year ago

Fix released. Thanks!