go-playground / validator

:100:Go Struct and Field validation, including Cross Field, Cross Struct, Map, Slice and Array diving
MIT License
16.14k stars 1.29k forks source link

URL validation fails for file:/// #1165

Open pklanka opened 10 months ago

pklanka commented 10 months ago

Package version eg. v9, v10: v10

Issue, Question or Enhancement: Issue

Code sample, to showcase or reproduce:


package main

import (
    "fmt"

    "github.com/go-playground/validator/v10"
)

type SampleStruct struct {
    FileUrl string `json:"file_url" validate:"omitempty,url"`
}

func main() {

    Validator := validator.New()
    sample := SampleStruct{
        FileUrl: "file://tmp/abcd",
    }
    if err := Validator.Struct(sample); err != nil {
        // this passes
        fmt.Println(err)
    }

    sample2 := SampleStruct{
        FileUrl: "file:///tmp/abcd",
    }
    if err := Validator.Struct(sample2); err != nil {
        // this fails
        fmt.Println(err)
    }
}
pklanka commented 10 months ago

file:///tmp/abcd should a valid file URL - ref: https://jkorpela.fi/fileurl.html