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

BranchClient does not escape special characters in branch names #245

Open
Khubajsn opened this issue Jun 13, 2022 · 1 comment
Open

BranchClient does not escape special characters in branch names #245

Khubajsn opened this issue Jun 13, 2022 · 1 comment

Comments

@Khubajsn
Copy link

When working with branch names that contain special characters (including but not limited to slashes), BranchClient performs incorrect HTTP requests.

URL encoding for the branchName parameter should be added to the following methods:

  • GetAsync
  • DeleteBranch
  • GetProtectedBranchesAsync
  • UnprotectBranchAsync
@Shineson1001
Copy link

Hi @Khubajsn
i think you have to URL-encoded the branch name link this:
... = System.Web.HttpUtility.UrlEncode(branchName)

GitLab documentation: File path, branches, and tags name encoding

But there is also a problem with the parser UriParser class in .NET 4.x if you use %2f in the URL

Workaround .. without warranty

        public async Task<T> Get<T>(string url)
        {
            System.Uri tmpUri = null;

            if (!url.ToLower().Contains("%2f"))
            {
                tmpUri = new System.Uri(url, System.UriKind.Relative);
            }
            else
            {
                string absoluteUri = string.Format("{0}{1}", _client.BaseAddress.AbsoluteUri, url);
                tmpUri = new System.Uri(absoluteUri);

                string paq = tmpUri.PathAndQuery; // you have to access to the PathAndQuery property
                System.Reflection.FieldInfo fieldInfoFlags = typeof(Uri).GetField("m_Flags", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
                ulong flags = (ulong)fieldInfoFlags.GetValue(tmpUri);
                flags &= ~((ulong)0x30); // Flags.PathNotCanonical (0x10) | Flags.QueryNotCanonical (0x20)
                fieldInfoFlags.SetValue(tmpUri, flags);
            }

            var responseMessage = await _client.GetAsync(tmpUri);
            await EnsureSuccessStatusCode(responseMessage);
            return await ReadResponse<T>(responseMessage);
        }

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

No branches or pull requests

2 participants