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

Incorrect TSR with mixed static and wildcard paths #2918

Closed
ibraheemdev opened this issue Oct 25, 2021 · 4 comments · Fixed by #2924
Closed

Incorrect TSR with mixed static and wildcard paths #2918

ibraheemdev opened this issue Oct 25, 2021 · 4 comments · Fixed by #2924

Comments

@ibraheemdev
Copy link
Contributor

The backtracking logic in #2897 is causing incorrect TSR values:

func TestTreeBacktrackingTsr(t *testing.T) {
	tree := &node{}
	tree.addRoute("/api/:page/:name", fakeHandler("1"))
	tree.addRoute("/api/hello/:name/bar/", fakeHandler("1"))
	res := tree.getValue("/api/hello/x/bar", getParams(), getSkippedNodes(), false)
	if res.tsr != true {
		t.Fatalf("expected tsr")
	}
}
--- FAIL: TestTreeBacktrackingTsr (0.00s)
    tree_test.go:855: expected tsr

I believe the TSR would have to be checked before backtracking.

@ibraheemdev
Copy link
Contributor Author

ibraheemdev commented Oct 25, 2021

Also, I don't know why this unrelated change was made in #2767:

-	value.tsr = (path == "/") ||
-			(len(prefix) == len(path)+1 && prefix[len(path)] == '/' &&
-				path == prefix[:len(prefix)-1] && n.handlers != nil)
+		value.tsr = path == "/" ||
+			(len(prefix) == len(path)+1 && n.handlers != nil)

It is causing simple tests to fail:

func TestTreeTsr(t *testing.T) {
	tree := &node{}
	tree.addRoute("/foo", fakeHandler("1"))
	tree.addRoute("/bar/", fakeHandler("1"))
	res := tree.getValue("/baz", getParams(), getSkippedNodes(), false)
	if res.tsr != false {
		t.Fatalf("unexpected tsr")
	}
}
--- FAIL: TestTreeTsr (0.00s)
    tree_test.go:855: unexpected tsr

@ibraheemdev
Copy link
Contributor Author

I have this fixed locally, I'll submit a PR.

@Bisstocuz
Copy link
Contributor

Bisstocuz commented Oct 26, 2021

I have this fixed locally, I'll submit a PR.

Great works, waiting for it.
#2847 fixed the second issue so you don't need to submit it again I think.

@zhuxi0511
Copy link
Contributor

I have this fixed locally, I'll submit a PR.

Thanks for your work, waiting for it!

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 a pull request may close this issue.

3 participants