Skip to content

Wrong replacing of '+' #28

Open
Open
@czesiu20

Description

@czesiu20

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions