Search code examples
goinstagraminstagram-api

Scandinavian characters not working in go-lang go-instagram API bindings


Hi I'm trying to wrap my head around what seems to be a problem with multibyte support in this open source library (https://github.com/carbocation/go-instagram/). I am using the code below to retrieve information about the tag blue in swedish. How ever I get an empty array when trying.

fmt.Println("Starting instagram download.")
client := instagram.NewClient(nil)
client.ClientID = "myid"
media, _, _ := client.Tags.RecentMedia("blå", nil)
fmt.Println(media)

I have tried using the api trough the browser and there are several pictures tagged with the tag. I have also tried using the code snippet with tags in English like blue and that returns the latest pictures as well. I would be glad if any one could explain why this might happen. Id like to update the lib so it supports multi-byte but I haven't got the go knowledge required. Is this a go problem or a problem with the library?

Thank you


Solution

  • The problem is in validTagName():

    // Strip out things we know Instagram won't accept. For example, hyphens.
    func validTagName(tagName string) (bool, error) {
        //\W matches any non-word character
        reg, err := regexp.Compile(`\W`)
        if err != nil {
            return false, err
        }
    
        if reg.MatchString(tagName) {
            return false, nil
        }
    
        return true, nil
    }
    

    In Go, \W matches precisely [^0-9A-Za-z_]. This validation check is incorrect.