uHttpSharp icon indicating copy to clipboard operation
uHttpSharp copied to clipboard

Wrong replacing of '+'

Open czesiu20 opened this issue 6 years ago • 0 comments

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.

czesiu20 avatar Apr 16 '19 11:04 czesiu20