Skip to content

+ not encoded in query string when using PHP_QUERY_RFC3986 #109

Description

@bennnjamin

Bug Report

Information Description
Package uri-components
Version 2.4.1
PHP version 8.1.2
OS Platform Ubuntu

Summary

I am trying to send phone numbers as query string parameters to communicate with a REST API and the request is failing because + is not encoded to %2B.

Standalone code, or other way to reproduce the problem

$queryPairs = [
    ["phone_number", "+18001231234"],
    ["special_characetrs", " /+t!q_"]
];
$queryString = QueryString::build($queryPairs, '&', PHP_QUERY_RFC1738);
print("League\URI PHP_QUERY_RFC1738 $queryString\n");
$queryString = QueryString::build($queryPairs, '&', PHP_QUERY_RFC3986);
print("League\URI PHP_QUERY_RFC3986 $queryString\n");

Expected result

The + character should be percent-encoded.

Actual result

League\URI PHP_QUERY_RFC1738 phone_number=%2B18001231234&special_characetrs=+%2F%2Bt%21q_
League\URI PHP_QUERY_RFC3986 phone_number=+18001231234&special_characetrs=%20/+t!q_

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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