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

connector/gitlab: Fix regexp in Link parser #1090

Merged
merged 1 commit into from
Oct 9, 2017

Conversation

lsjostro
Copy link

Fix regression in Link parser.
.* is to ambiguous.

@ericchiang
Copy link
Contributor

Can you add a test?

@lsjostro
Copy link
Author

Added test

Copy link
Contributor

@ericchiang ericchiang left a comment

Choose a reason for hiding this comment

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

Build failing because of golint.

Mind addressing that then squashing your commits?

)

func TestNextURL(t *testing.T) {
linkHeader := "<https://gitlab.com/api/v4/groups?page=3&per_page=20>; rel=\"next\", " +
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: we generally prefer table driven tests https://github.com/golang/go/wiki/TableDrivenTests

If you want to add that here that works, if not I'm fine with the test as is.

Copy link
Author

Choose a reason for hiding this comment

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

I'll fix! Thanks!

} else {
break
func nextURL(url string, link string) string {
reNext := regexp.MustCompile("<([^>]+)>; rel=\"next\"")
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: move these to global vars so we don't re-compile them every time the function is called

var (
    reNext = regexp.MustCompile("...")
    reLast = regexp.MustCompile("...")
)

func nextURL() {
    // .. use reNext and reLast
}

Copy link
Author

Choose a reason for hiding this comment

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

Will do!


if len(reNext.FindStringSubmatch(link)) > 1 {
return reNext.FindStringSubmatch(link)[1]
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

go lint picked this up as fishy

/home/travis/gopath/src/github.com/coreos/dex/connector/gitlab/gitlab.go:296:9: if block ends with a return statement, so drop this else and outdent its block
Found 1 lint suggestions; failing.

@lsjostro
Copy link
Author

squashed and fixed the above comments

@lsjostro lsjostro changed the title connector/gitlab: Fix for to ambigious regexp in Link parser connector/gitlab: Fix regexp in Link parser Sep 29, 2017
Copy link
Contributor

@ericchiang ericchiang left a comment

Choose a reason for hiding this comment

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

lgtm

@lsjostro
Copy link
Author

Awesome! Thanks! Looking forward to a patch release soon then.
I have it hot patched in prod currently.

@lsjostro
Copy link
Author

lsjostro commented Oct 4, 2017

@ericchiang when can we expect this merged?

@ericchiang
Copy link
Contributor

@lsjostro sorry was out of the office.

@ericchiang ericchiang merged commit 9c176dd into dexidp:master Oct 9, 2017
mmrath pushed a commit to mmrath/dex that referenced this pull request Sep 2, 2019
connector/gitlab: Fix regexp in Link parser
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.

2 participants