New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
File validation not working? #24
Comments
Go version:go version go1.10 darwin/amd64 Govalidator version:v1.8 Codepackage main
import (
"encoding/json"
"fmt"
"net/http"
"github.com/thedevsaddam/govalidator"
)
func handler(w http.ResponseWriter, r *http.Request) {
rules := govalidator.MapData{
"file:photo": []string{"ext:jpg,png", "size:10000", "mime:jpg,png"},
}
messages := govalidator.MapData{
"file:photo": []string{"ext:Only jpg/png is allowed", "required:Photo is required"},
}
opts := govalidator.Options{
Request: r, // request object
Rules: rules, // rules map,
Messages: messages,
}
v := govalidator.New(opts)
e := v.Validate()
err := map[string]interface{}{"validationError": e}
w.Header().Set("Content-type", "applciation/json")
json.NewEncoder(w).Encode(err)
}
func main() {
http.HandleFunc("/", handler)
fmt.Println("Listening on port: 9999")
http.ListenAndServe(":9999", nil)
} Response:
|
@thedevsaddam ill double check, will inform u afterward |
I can assure you that the bug really exist.
When u submit the form without uploading any file, u will get : Another bug, when u explicitly put The validation seem to be working before this..When i pull the latest code from your repos, it break everything. #18 possible cause? |
@slier81 Hope it'll work now. Please check from master branch and if it's okay then I'll tag this commit as |
@thedevsaddam eh i thought u waiting for my PR? nvm ill check it, and confirm with u afterwards |
@thedevsaddam Yes everything is working as expected.Thank you for your hard work..You can tag this commit as |
Hey adam..
I think the form validation is not working when the rules is optional (no
required
)Eventhough im not uploading any file, the validation still run through yielding me to
Only jpg/png is allowed
Regarding this line:
https://github.com/thedevsaddam/govalidator/blob/master/validator.go#L95
Even though there is no uploaded file,
file
is still not nilI think the correct way should be
Some additional info:
Golang v1.10
I'm entirely not sure prior to v1.10 whether its working or not
The text was updated successfully, but these errors were encountered: