Skip to content

fix: Escape package names in UsersService methods - #4546

Open
pucedoteth wants to merge 1 commit into
google:masterfrom
pucedoteth:fix-escape-user-package-names-v2
Open

fix: Escape package names in UsersService methods#4546
pucedoteth wants to merge 1 commit into
google:masterfrom
pucedoteth:fix-escape-user-package-names-v2

Conversation

@pucedoteth

Copy link
Copy Markdown

UsersService.GetPackage escapes packageName, but the other seven package methods interpolate it raw, so a name containing a slash produces a malformed path. Container and scoped npm package names routinely contain one.

OrganizationsService already escapes it in all seven equivalent methods and documents it, so this just brings the user methods in line: 12 call sites escaped, plus the same doc note.

The existing tests missed this because only the GetPackage test uses a slashed name (hello/hello_docker); the rest use hello_docker. The new test uses a slashed name against every affected method — all ten sub-cases fail without the change and pass with it.

AI assistance: Claude Code found the inconsistency, made the edits, and drafted the test and this description. I reviewed the diff and ran script/fmt.sh, script/generate.sh (no drift), script/lint.sh and script/test.sh.

GetPackage escaped packageName but the other seven UsersService package
methods interpolated it raw, so a name containing a slash produced a
malformed path. Container and scoped npm package names routinely contain
one. OrganizationsService already escapes it in all seven equivalent
methods, so this brings the user methods in line and adds the same doc
note.
@gmlewis gmlewis added the NeedsReview PR is awaiting a review before merging. label Sep 11, 2026
@codecov

codecov Bot commented Sep 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.54%. Comparing base (2433615) to head (c2d06a8).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #4546   +/-   ##
=======================================
  Coverage   98.54%   98.54%           
=======================================
  Files         196      196           
  Lines       17938    17938           
=======================================
  Hits        17677    17677           
  Misses        261      261           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@gmlewis gmlewis left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you, @pucedoteth!
LGTM.
Awaiting second LGTM+Approval from any other contributor to this repo before merging.

cc: @stevehipwell - @Not-Dhananjay-Mishra

Comment thread github/users_packages.go
// GetPackage gets a package by name for a user. Passing the empty string for "user" will
// get the package for the authenticated user.
//
// Note that packageName is escaped for the URL path so that you don't need to.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Note that packageName is escaped for the URL path so that you don't need to.
// Note: the packageName is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscap .

For consistency with rest of the repo.

// ListRulesForBranch gets all the repository rules that apply to the specified branch.
//
// Note: the branch name is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscape .
//
// GitHub API docs: https://docs.github.com/rest/repos/rules?apiVersion=2022-11-28#get-rules-for-a-branch
//
//meta:operation GET /repos/{owner}/{repo}/rules/branches/{branch}
func (s *RepositoriesService) ListRulesForBranch(ctx context.Context, owner, repo, branch string, opts *ListOptions) (*BranchRules, *Response, error) {

Same applies to other occurrences in this PR.

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

Labels

NeedsReview PR is awaiting a review before merging.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants