Skip to content

'127.0.0.1:' on tag 'tcp4_addr' #1003

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

Open
fx-slayer opened this issue Sep 27, 2022 · 4 comments
Open

'127.0.0.1:' on tag 'tcp4_addr' #1003

fx-slayer opened this issue Sep 27, 2022 · 4 comments

Comments

@fx-slayer
Copy link

  • [Y] I have looked at the documentation here first?

  • [Y] I have looked at the examples provided that may showcase my question here?

Package version eg. v9, v10:

V10

Issue, Question or Enhancement:

Is '127.0.0.1:' a valid Tcp4 address? Basically I don't see any sense, if there is any RFC section or reasonable explanation ,i'm glad to know.

Code sample, to showcase or reproduce:

func TestTCP_ADDR(t *testing.T) {
	e := validator.New().Var("127.0.0.1:", "tcp4_addr")
	if e == nil {
		t.Fatal(e)
	}
}

=== RUN   TestTCP_ADDR
    common_test.go:119: <nil>
--- FAIL: TestTCP_ADDR (0.00s)
FAIL
exit status 1
@zemzale
Copy link
Member

zemzale commented Oct 5, 2022

@7a6bb3ef3 Hi.

I actually can't find any specification about this, but the Go net library is used here for that, and it parses the address and leaves the port at 0. I don't know if that is correct or not by spec or just a mistake on the Go libraries part.

A similar code on rust fails because that probably is not a valid address.

I will see what can be done about this.

@fx-slayer
Copy link
Author

I have opened an issues in golang/go, they mentioned #13610 , actually I'm confused about this problem.

what ever ,#13610 may help you.

@zemzale
Copy link
Member

zemzale commented Oct 13, 2022

As far as I understand it's basically a Go stdlib thing, where if the port is left empty it assumes port 0.

It would still work with net code in your app, but I can see how from a validation standpoint that is not factually correct. I think in that case we should add some extra steps to validation where we check if the part after the port is empty.

@salleh
Copy link

salleh commented Apr 8, 2023

I have opened an issues in golang/go, they mentioned #13610 , actually I'm confused about this problem.

what ever ,#13610 may help you.

I guess the existing state of the logic for saying "X.X.X.X:" is a valid tcp4_addr is to not opinionated the validation rule as different underlying platforms behave slightly different from each other in dealing with 'blank' port specification. That is what I understand from reading #13610.

Hence yes, as pointed out by @zemzale, perhaps developers are to consciously aware whether their intended code target will honour the rule or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants