kreait / firebase-php

Unofficial Firebase Admin SDK for PHP
https://firebase-php.readthedocs.io/
MIT License
2.24k stars 427 forks source link

Database::getReference() without leading slash throws InvalidArgumentException #663

Closed gampig closed 2 years ago

gampig commented 2 years ago

Describe the issue you are experiencing

When calling Database::getReference() without a leading slash, e.g. getReference('clothes'), an InvalidArgumentException is thrown with the message 'The path of a URI with an authority must start with a slash "/" or be empty'.

Installed packages

fig/http-message-util 1.1.5 Utility classes and constants for use with PSR-7 (psr/http-message) firebase/php-jwt v5.4.0 A simple library to encode and decode JSON Web Tokens (JWT) in PHP. Should conform to the current spec. google/auth v1.18.0 Google Auth Library for PHP google/cloud-core v1.43.0 Google Cloud PHP shared dependency, providing functionality useful to all components. google/cloud-storage v1.25.1 Cloud Storage Client for PHP google/crc32 v0.1.0 Various CRC32 implementations guzzlehttp/guzzle 7.3.0 Guzzle is a PHP HTTP client library guzzlehttp/promises 1.4.1 Guzzle promises library guzzlehttp/psr7 2.0.0 PSR-7 message implementation that also provides common utility methods kreait/clock 1.1.0 A PHP 7.0 compatible clock abstraction kreait/firebase-php 5.23.0 Firebase Admin SDK kreait/firebase-tokens 1.16.1 A library to work with Firebase tokens lcobucci/clock 2.0.0 Yet another clock abstraction lcobucci/jwt 4.0.4 A simple library to work with JSON Web Token and JSON Web Signature monolog/monolog 2.3.5 Sends your logs to files, sockets, inboxes, databases and various web services mtdowling/jmespath.php 2.6.1 Declaratively specify how to extract elements from a JSON document psr/cache 1.0.1 Common interface for caching libraries psr/http-client 1.0.1 Common interface for HTTP clients psr/http-factory 1.0.1 Common interfaces for PSR-7 HTTP message factories psr/http-message 1.0.1 Common interface for HTTP messages psr/log 1.1.4 Common interface for logging libraries psr/simple-cache 1.0.1 Common interfaces for simple caching ralouphie/getallheaders 3.0.3 A polyfill for getallheaders. riverline/multipart-parser 2.0.8 One class library to parse multipart content with encoding and charset support. rize/uri-template 0.3.3 PHP URI Template (RFC 6570) supports both expansion & extraction smarty/smarty v3.1.39 Smarty - the compiling PHP template engine symfony/polyfill-mbstring v1.23.1 Symfony polyfill for the Mbstring extension symfony/polyfill-php80 v1.23.1 Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions

PHP version and extensions

composer-plugin-api 2.0.0 The Composer Plugin API composer-runtime-api 2.0.0 The Composer Runtime API ext-bcmath 7.4.9 The bcmath PHP extension ext-bz2 7.4.9 The bz2 PHP extension ext-calendar 7.4.9 The calendar PHP extension ext-ctype 7.4.9 The ctype PHP extension ext-curl 7.4.9 The curl PHP extension ext-date 7.4.9 The date PHP extension ext-dom 20031129 The dom PHP extension ext-exif 7.4.9 The exif PHP extension ext-filter 7.4.9 The filter PHP extension ext-ftp 7.4.9 The ftp PHP extension ext-hash 7.4.9 The hash PHP extension ext-iconv 7.4.9 The iconv PHP extension ext-imap 7.4.9 The imap PHP extension ext-intl 7.4.9 The intl PHP extension ext-json 7.4.9 The json PHP extension ext-libxml 7.4.9 The libxml PHP extension ext-mbstring 7.4.9 The mbstring PHP extension ext-mysqli 7.4.9 The mysqli PHP extension ext-mysqlnd 0 The mysqlnd PHP extension (actual version: mysqlnd 7.4.9) ext-openssl 7.4.9 The openssl PHP extension ext-pcre 7.4.9 The pcre PHP extension ext-pdo 7.4.9 The PDO PHP extension ext-pdo_mysql 7.4.9 The pdo_mysql PHP extension ext-phar 7.4.9 The Phar PHP extension ext-readline 7.4.9 The readline PHP extension ext-reflection 7.4.9 The Reflection PHP extension ext-session 7.4.9 The session PHP extension ext-simplexml 7.4.9 The SimpleXML PHP extension ext-spl 7.4.9 The SPL PHP extension ext-tokenizer 7.4.9 The tokenizer PHP extension ext-xml 7.4.9 The xml PHP extension ext-xmlreader 7.4.9 The xmlreader PHP extension ext-xmlwriter 7.4.9 The xmlwriter PHP extension ext-zip 1.15.6 The zip PHP extension ext-zlib 7.4.9 The zlib PHP extension lib-bz2 1.0.8 The bz2 library lib-curl 7.70.0 The curl library lib-curl-libssh2 1.9.0 curl libssh2 version lib-curl-openssl 1.1.1.7 curl OpenSSL version (1.1.1.7) lib-curl-zlib 1.2.11 curl zlib version lib-date-timelib 2018.03 date timelib version lib-date-zoneinfo 2020.1 zoneinfo ("Olson") database for date lib-iconv 1.16 The iconv library lib-icu 66.1 The ICU unicode and globalization support library lib-icu-cldr 36.1 ICU CLDR project version lib-icu-unicode 13.0.0 ICU unicode version lib-icu-zoneinfo 2019.3 zoneinfo ("Olson") database for icu lib-libxml 2.9.10 libxml library version lib-mbstring-libmbfl 1.3.2 mbstring libmbfl version lib-mbstring-oniguruma 6.9.4 mbstring oniguruma version lib-openssl 1.1.1.7 OpenSSL 1.1.1g 21 Apr 2020 lib-pcre 10.34 The pcre library lib-pcre-unicode 12.1.0 PCRE Unicode version support lib-zip-libzip 1.5.2 The zip-libzip library lib-zlib 1.2.11 The zlib library php 7.4.9 The PHP interpreter php-64bit 7.4.9 The PHP interpreter, 64bit php-ipv6 7.4.9 The PHP interpreter, with IPv6 support php-zts 7.4.9 The PHP interpreter, with Zend Thread Safety

On which operating system(s) does the issue occur?

Steps to reproduce the issue.

With $db being an instance of Database, call $db->getReference('example/path'). It is also caused at the integration tests, as seen here.

Error message/Stack trace

#0 [...]/vendor/guzzlehttp/psr7/src/Uri.php(492): GuzzleHttp\Psr7\Uri->validateState()
#1 [...]/vendor/kreait/firebase-php/src/Firebase/Database.php(39): GuzzleHttp\Psr7\Uri->withPath('clothes')
#2 [...]: Kreait\Firebase\Database->getReference('clothes')

Additional information

Whenever kreait/firebase-php calls $uri->withPath(), it does not add a leading slash to the parameter. However, guzzle's validateState(), which is called by $uri->withPath(), expects a leading slash, thus it throws the exception since version 2.0.0.

jeromegamez commented 2 years ago

Hey @gampig and thank you for reporting this issue! I just released 5.24 which should fix it 😂 , please let me know if it does! 🙏

gampig commented 2 years ago

It did, thank you!