#13830·appwrite

Uri::__toString() in packages/psr7 produces invalid/malformed URIs for rootless and double-slash paths

Author: Indra55Created Sep 22, 2026Updated Sep 23, 2026
Labelsproduct / databasesproduct / authproduct / vcs

Reproduction steps

This affects Utopia\Psr7\Uri in packages/psr7/src/Uri.php (the PSR-7 implementation absorbed into the monorepo in #13723).

  1. Construct a Uri with an authority (host) and a path that does not start with /:
php
   $uri = new Uri('http', '', 'example.com', null, 'foo/bar', '', '');
   echo (string) $uri;
  1. Separately, construct a Uri with no authority and a path that starts with //:
php
   $uri2 = new Uri('', '', '', null, '//foo/bar', '', '');
   echo (string) $uri2;

Expected behavior

Per the PSR-7 UriInterface::__toString() contract (which this class implements), __toString() must adjust the path in two cases before concatenating it, since PHP can't throw from __toString():

  • If the path is rootless and an authority is present, the path MUST be prefixed with /.
  • If the path starts with more than one / and no authority is present, the leading slashes MUST be reduced to one.

So:

  • Case 1 should render as http://example.com/foo/bar
  • Case 2 should render as /foo/bar

Both should also be re-parseable back into an equivalent URI.

Actual Behavior

Neither adjustment is made, so __toString() produces invalid, and in one case silently corrupted, output:

  • Case 1 renders as http://example.comfoo/bar — the host and path are fused into one unparsable token.
  • Case 2 renders as //foo/bar — re-parsing this string treats foo as the authority/host and /bar as the path, silently losing the original path data.

There is currently no UriTest.php in packages/psr7/tests/, so this wasn't caught by the existing suite.

Appwrite version

Appwrite Cloud

Operating system

Linux

Your Environment

  • Package: packages/psr7 (mirrored as utopia-php/psr7)
  • PHP 8.3.6
  • No customizations — reproduced against a clean clone of appwrite/appwrite main with a standalone PHP harness instantiating Utopia\Psr7\Uri directly (no Docker stack needed to reproduce).

Have you spent some time to check if this issue has been raised before?

  • I checked and didn't find similar issue

Have you read the Code of Conduct?