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

net/url: comment of split function is wrong #35735

Closed
jinmiaoluo opened this issue Nov 21, 2019 · 2 comments
Closed

net/url: comment of split function is wrong #35735

jinmiaoluo opened this issue Nov 21, 2019 · 2 comments
Labels
Documentation FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@jinmiaoluo
Copy link
Contributor

jinmiaoluo commented Nov 21, 2019

What did you expect to see?

// split slices s into two substrings separated by the first occurrence of
// sep. If cutc is true then sep is excluded from the second substring.
// If sep does not occur in s then s and the empty string is returned.
func split(s string, sep byte, cutc bool) (string, string) {
	i := strings.IndexByte(s, sep)
	if i < 0 {
		return s, ""
	}
	if cutc {
		return s[:i], s[i+1:]
	}
	return s[:i], s[i:]
}

What did you see instead?

// split slices s into two substrings separated by the first occurrence of
// sep. If cutc is true then sep is included with the second substring.
// If sep does not occur in s then s and the empty string is returned.
func split(s string, sep byte, cutc bool) (string, string) {
	i := strings.IndexByte(s, sep)
	if i < 0 {
		return s, ""
	}
	if cutc {
		return s[:i], s[i+1:]
	}
	return s[:i], s[i:]
}

go/src/net/url/url.go

Lines 454 to 466 in 39a9cb4

// split slices s into two substrings separated by the first occurrence of
// sep. If cutc is true then sep is included with the second substring.
// If sep does not occur in s then s and the empty string is returned.
func split(s string, sep byte, cutc bool) (string, string) {
i := strings.IndexByte(s, sep)
if i < 0 {
return s, ""
}
if cutc {
return s[:i], s[i+1:]
}
return s[:i], s[i:]
}

@ALTree
Copy link
Member

ALTree commented Nov 21, 2019

It appears you are right.

In 5ff12f6 the comment was changed from

return t, c u (or t, u if cutc == true).

which implies that c is excluded from the 2nd string if cutc == true, to

If cutc is true then sep is included with the second substring.

which says the opposite thing.

@ALTree ALTree added Documentation NeedsFix The path to resolution is known, but the work has not been done. labels Nov 21, 2019
@ALTree ALTree added this to the Backlog milestone Nov 21, 2019
@jinmiaoluo jinmiaoluo changed the title net/url: comment of split function is wrong. net/url: comment of split function is wrong Nov 21, 2019
@gopherbot
Copy link

Change https://golang.org/cl/208297 mentions this issue: net/url: update net/url split comment

jinmiaoluo pushed a commit to jinmiaoluo/go that referenced this issue Nov 21, 2019
@golang golang locked and limited conversation to collaborators Nov 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Documentation FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants