Skip to content

fix: Escape package names in UsersService methods - #4546

Merged
gmlewis merged 2 commits into
google:masterfrom
pucedoteth:fix-escape-user-package-names-v2
Sep 12, 2026
Merged

fix: Escape package names in UsersService methods#4546
gmlewis merged 2 commits into
google:masterfrom
pucedoteth:fix-escape-user-package-names-v2

Conversation

@pucedoteth

Copy link
Copy Markdown
Contributor

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.57%. Comparing base (2433615) to head (5d36ebb).
⚠️ Report is 4 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4546      +/-   ##
==========================================
+ Coverage   98.54%   98.57%   +0.02%     
==========================================
  Files         196      197       +1     
  Lines       17938    18252     +314     
==========================================
+ Hits        17677    17991     +314     
  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 Outdated
// 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.

@pucedoteth

Copy link
Copy Markdown
Contributor Author

Good catch, thanks — applied to all 8 occurrences in 5d36ebb.

I'd matched orgs_packages.go, the sibling file, but you're right that it's the outlier: repo-wide the // Note: the X name is URL path escaped for you. form appears 55 times across 7 files, against 7 in that one file.

Two small deviations from the literal suggestion, both to match the source you linked:

  • The suggested URL ends #PathEscap; I used #PathEscape so the link resolves.
  • I used "the package name" rather than "the packageName", matching "the branch name" and "the environment name" in the existing notes.

The result is byte-identical to the repos_rules.go note apart from the noun.

@gmlewis gmlewis removed the NeedsReview PR is awaiting a review before merging. label Sep 12, 2026
@gmlewis
gmlewis merged commit 440bc88 into google:master Sep 12, 2026
15 checks passed
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