langgenius / dify

Dify is an open-source LLM app development platform. Dify's intuitive interface combines AI workflow, RAG pipeline, agent capabilities, model management, observability features and more, letting you quickly go from prototype to production.
https://dify.ai
Other
52.67k stars 7.71k forks source link

gitlab tool file url not correctly encoded #10995

Closed AkisAya closed 2 days ago

AkisAya commented 3 days ago

Self Checks

Dify version

main

Cloud or Self Hosted

Self Hosted (Source)

Steps to reproduce

use gitlab tool in a workflow input a path check result

✔️ Expected Behavior

return files and it's content

❌ Actual Behavior

emtpy result and backend server report file not found

dosubot[bot] commented 3 days ago

The issue you're experiencing with the GitLab tool in the Dify self-hosted version, where file URLs are not correctly encoded, resulting in an empty result and a "file not found" error, is likely due to incorrect URL encoding of the file paths. In the fetch_files method, while the repository identifier is URL encoded, the file paths (item_path) are not encoded when constructing the file_url. This can lead to issues if the file paths contain special characters that need to be URL encoded.

To fix this, ensure that item_path is URL encoded when constructing the file_url. Here is the relevant part of the code with the necessary change:

import urllib.parse

# ...

if is_repository:
    file_url = (
        f"{domain}/api/v4/projects/{encoded_identifier}/repository/files"
        f"/{urllib.parse.quote(item_path, safe='')}/raw?ref={branch}"
    )
else:
    file_url = (
        f"{domain}/api/v4/projects/{project_id}/repository/files/"
        f"{urllib.parse.quote(item_path, safe='')}/raw?ref={branch}"
    )

By URL encoding item_path, you ensure that any special characters in the file path are correctly handled, which should resolve the "file not found" issue [1].

To continue talking to Dosu, mention @dosu.