Skip to content
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

Not correct FQDN validation #1218

Open
2 tasks done
nao99 opened this issue Feb 1, 2024 · 0 comments
Open
2 tasks done

Not correct FQDN validation #1218

nao99 opened this issue Feb 1, 2024 · 0 comments

Comments

@nao99
Copy link

nao99 commented Feb 1, 2024

  • I have looked at the documentation here first?
  • I have looked at the examples provided that may showcase my question here?

v10:

Hi everyone

I just noticed the FQDN validator doesn't work properly
It accepts the "-" symbol at the ends of n domain level

I searched is this planned or any other github issue was already created, but I didn't find anything similar

Issue, Question or Enhancement:

Here you can see screenshots the regex is satisfies with a "domain-.com" example

telegram-cloud-photo-size-2-5321297685145310438-y
telegram-cloud-photo-size-2-5321297685145310439-y

Code sample, to showcase or reproduce:

package main

import (
	"fmt"
	"github.com/go-playground/validator/v10"
)

func main() {
	validate := validator.New()

	err := validate.Var("google.com", "required,fqdn")
	if err != nil {
		fmt.Println(err.Error())
		return
	}

	err = validate.Var("google-.com", "required,fqdn")
	if err != nil {
		fmt.Println(err.Error())
		return
	}

	fmt.Println("Everything is ok, but it shouldn't cause the \"google-.com\" is not looking as a valid domain name")

	err = validate.Var("-google.com", "required,fqdn")
	if err != nil {
		fmt.Printf("For example, this is invalid as expected: %s", err.Error())
		return
	}
}

Possible solution:

I found a regex which can possibly resolve this issue (but I didn't test anything except the regex itself via regex101)
https://stackoverflow.com/questions/10306690/what-is-a-regular-expression-which-will-match-a-valid-domain-name-without-a-subd

Screenshot 2024-02-01 at 12 06 10

@nao99 nao99 changed the title Is not correct FQDN validation Not correct FQDN validation Feb 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant