Skip to content

Wrong replacing of '+' #28

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

Open
czesiu20 opened this issue Apr 16, 2019 · 0 comments
Open

Wrong replacing of '+' #28

czesiu20 opened this issue Apr 16, 2019 · 0 comments

Comments

@czesiu20
Copy link

When parsing the query, the replacement operation of the '+' character should be performed before URI decoding. BASE64 encoded string in the query can contain '+' character which is currently replaced, so the BASE64 value is corrupted.

    public QueryStringHttpHeaders(string query)
    {
        var splittedKeyValues = query.Split(Seperators, StringSplitOptions.RemoveEmptyEntries);
        var values = new Dictionary<string, string>(splittedKeyValues.Length / 2, StringComparer.InvariantCultureIgnoreCase);

        for (int i = 0; i < splittedKeyValues.Length; i += 2)
        {
            var key = Uri.UnescapeDataString(splittedKeyValues[i]);
            string value = null;
            if (splittedKeyValues.Length > i + 1)
            {
                value = Uri.UnescapeDataString(splittedKeyValues[i + 1]).Replace('+', ' ');  
            }
            values[key] = value;
        }
        _count = values.Count;
        _child = new HttpHeaders(values);
    }

The replacing should be modified as follows:
value = Uri.UnescapeDataString(splittedKeyValues[i + 1].Replace('+', ' '));

Additionally using the StringSplitOptions.RemoveEmptyEntries option can cause errors in the case the value is empty. I think it should be replaced by StringSplitOptions.None.

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

1 participant