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

Fix parse monitor URL #21

Closed
wants to merge 4 commits into from
Closed

Fix parse monitor URL #21

wants to merge 4 commits into from

Conversation

lifenod
Copy link
Contributor

@lifenod lifenod commented Dec 27, 2018

url.Parse will fail when to parse Lacoste3 INFLUXDB_URL, error is net/url: invalid userinfo.

Because Lacoste3 userinfo contain invalid character ], see detail https://github.com/golang/go/blob/6a64efc25004175e198e75191e215a7b1a08a2fa/src/net/url/url.go#L1115.

I write a regexp to capture config.

@lifenod lifenod self-assigned this Dec 27, 2018
@lifenod lifenod requested a review from junhuif December 27, 2018 16:57
@lifenod lifenod requested review from junhuif and bodhi and removed request for junhuif and bodhi December 28, 2018 03:01
@lifenod lifenod requested a review from junhuif December 28, 2018 03:47
Copy link
Member

@junhuif junhuif left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems it's quite common to use url.Parse to parse the URL configuration, for example

So, I think it's more useful to change that password instead of modifying the code.

@lifenod
Copy link
Contributor Author

lifenod commented Dec 28, 2018

Let's change back, and abstract a parseConfig function.

@bodhi
Copy link
Member

bodhi commented Dec 28, 2018

It seems it's quite common to use url.Parse to parse the URL configuration

Agree with this.

Because Lacoste3 userinfo contain invalid character ]

So if we define the input as a URL, then ] should be escaped, as it says in the comment above the linked function (and in the RFC):

// validUserinfo reports whether s is a valid userinfo string per RFC 3986
// Section 3.2.1:
//     userinfo    = *( unreserved / pct-encoded / sub-delims / ":" )
//     unreserved  = ALPHA / DIGIT / "-" / "." / "_" / "~"
//     sub-delims  = "!" / "$" / "&" / "'" / "(" / ")"
//                   / "*" / "+" / "," / ";" / "="

so ] should be %5D, and it's decoded by url.Userinfo: https://play.golang.org/p/7D8BCvdizYZ

package main

import (
	"fmt"
	"net/url"
)

func main() {
	u, e := url.Parse("http://hello%5d:password@example.com")
	fmt.Println(u, e)
	fmt.Println(u.User.Username())
}

output:

http://hello%5D:password@example.com <nil>
hello]

@lifenod
Copy link
Contributor Author

lifenod commented Jan 2, 2019

Let's escape the URL.

@lifenod lifenod closed this Jan 2, 2019
@lifenod lifenod deleted the fix-parse-monitor-url branch January 7, 2019 08:16
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

Successfully merging this pull request may close these issues.

3 participants