Skip to content

[4.6] Slashes in file path used in Src and Downloads API classes are url-encoded #83

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

Merged
merged 3 commits into from
Mar 17, 2024

Conversation

zolhorvath
Copy link
Contributor

Slashes in file path used in Src and Downloads API classes are url-encoded, which makes it impossible to get metadata or get the content of files from a repository unless the file is in the project root.

For example, in case of \Bitbucket\Api\Repositories\Workspaces\Src::download(), if I want to download a file from my project's subfolder:

$this->client->repositories()
    ->workspaces('my-workspace')
    ->src('my-project')
    ->download('main', 'docs/foo/BAR.md');

...then I expect that the client fetches the data from the URI string https://api.bitbucket.org/2.0/repositories/my-workspace/my-project/src/main/docs/foo/BAR.md,

but the URI string will be https://api.bitbucket.org/2.0/repositories/my-workspace/my-project/src/main/docs%2Ffoo%2FBAR.md, which will obviously fail to return the file's content (and throws an API error instead).

Methods affected:

  • \Bitbucket\Api\Repositories\Workspaces\Src::show()
  • \Bitbucket\Api\Repositories\Workspaces\Src::download()
  • \Bitbucket\Api\Repositories\Workspaces\Downloads::download()
  • \Bitbucket\Api\Repositories\Workspaces\Downloads::remove()

Added a new test which hopefully describes my issue more clearly.

Asking for a review, and last but not least, thank you for this Bitbucket Client!

@GrahamCampbell
Copy link
Member

Thanks for the report. It's a shame some Bitbucket APIs expect the slashes to be encoded, and some not. I don't have time to check this, but I trust you've confirmed your changes to work for these APIs, so I'm happy to merge on that basis.

@GrahamCampbell GrahamCampbell changed the title Slashes in file path used in Src and Downloads API classes are url-encoded [4.6] Slashes in file path used in Src and Downloads API classes are url-encoded Mar 17, 2024
@GrahamCampbell GrahamCampbell merged commit 894c422 into BitbucketPHP:4.6 Mar 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants