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

[API] File upload does not work properly #3359

Open
csisy opened this issue Sep 4, 2023 · 0 comments
Open

[API] File upload does not work properly #3359

csisy opened this issue Sep 4, 2023 · 0 comments
Labels
APIv3 GitHub compatible API bug
Milestone

Comments

@csisy
Copy link

csisy commented Sep 4, 2023

Issue

Impacted version: 4.39.0 (current latest)

Deployment mode: Self-hosted, API request

Problem description:

With the file content (upload) API, the given path is inproperly trimmed (twice), see:

val path = paths.take(paths.size - 1).toList.mkString("/")

For example with the url /api/v3/repos/<owner>/<repo>/contents/subfolder/test.md the linked code results in the following execution flow:

  • paths will be ['subfolder', 'test.md']
  • path will be subfolder (all elements except last joined with /)
  • getFileInfo is called with subfolder
    • this tries to trim the filename from the given path, resulting in . directory and subfolder filename
    • since subfolder is an existing folder in the root, the code is interpreted as trying to "update" a "file" with subfolder filename to the root directory

This is a consequence of a previous refactor which introduced the getFileInfo call #2802

The solution itself would be to directly pass the result of multiParams("splat") to the getFileInfo so it can appropriately determine the directory and filename.

val fullPath = multiParams("splat").head;
val paths = fullPath.split("/")
val path = paths.take(paths.size - 1).toList.mkString("/")

// ...

  val fileInfo = getFileInfo(git, commit, fullPath, false)
@takezoe takezoe added bug APIv3 GitHub compatible API labels Oct 22, 2023
@takezoe takezoe added this to the 4.41.0 milestone Oct 22, 2023
@takezoe takezoe modified the milestones: 4.41.0, 4.42.0 May 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
APIv3 GitHub compatible API bug
Development

No branches or pull requests

2 participants