From 3e8ce80f806f219c70d9ced83af22798fd396c7c Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 15 Aug 2021 19:13:26 +0200 Subject: [PATCH] Fixed numeric query params being replaced by 0 in long URLs --- CHANGELOG.md | 17 +++++++++++++++++ .../Helper/ShortUrlRedirectionBuilder.php | 5 +++-- .../Helper/ShortUrlRedirectionBuilderTest.php | 2 ++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 46a3b884..323e4bcc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,23 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com), and this project adheres to [Semantic Versioning](https://semver.org). +## [2.8.1] - 2021-08-15 +### Added +* *Nothing* + +### Changed +* *Nothing* + +### Deprecated +* *Nothing* + +### Removed +* *Nothing* + +### Fixed +* [#1155](https://github.com/shlinkio/shlink/issues/1155) Fixed numeric query params in long URLs being replaced by `0`. + + ## [2.8.0] - 2021-08-04 ### Added * [#1089](https://github.com/shlinkio/shlink/issues/1089) Added new `ENABLE_PERIODIC_VISIT_LOCATE` env var to docker image which schedules the `visit:locate` command every hour when provided with value `true`. diff --git a/module/Core/src/ShortUrl/Helper/ShortUrlRedirectionBuilder.php b/module/Core/src/ShortUrl/Helper/ShortUrlRedirectionBuilder.php index 43ea4993..f83a7eb9 100644 --- a/module/Core/src/ShortUrl/Helper/ShortUrlRedirectionBuilder.php +++ b/module/Core/src/ShortUrl/Helper/ShortUrlRedirectionBuilder.php @@ -5,11 +5,11 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Core\ShortUrl\Helper; use GuzzleHttp\Psr7\Query; +use Laminas\Stdlib\ArrayUtils; use League\Uri\Uri; use Shlinkio\Shlink\Core\Entity\ShortUrl; use Shlinkio\Shlink\Core\Options\TrackingOptions; -use function array_merge; use function sprintf; class ShortUrlRedirectionBuilder implements ShortUrlRedirectionBuilderInterface @@ -37,7 +37,8 @@ class ShortUrlRedirectionBuilder implements ShortUrlRedirectionBuilderInterface unset($currentQuery[$disableTrackParam]); } - $mergedQuery = array_merge($hardcodedQuery, $currentQuery); + // We want to merge preserving numeric keys, as some params might be numbers + $mergedQuery = ArrayUtils::merge($hardcodedQuery, $currentQuery, true); return empty($mergedQuery) ? null : Query::build($mergedQuery); } diff --git a/module/Core/test/ShortUrl/Helper/ShortUrlRedirectionBuilderTest.php b/module/Core/test/ShortUrl/Helper/ShortUrlRedirectionBuilderTest.php index c64147c1..985a3cea 100644 --- a/module/Core/test/ShortUrl/Helper/ShortUrlRedirectionBuilderTest.php +++ b/module/Core/test/ShortUrl/Helper/ShortUrlRedirectionBuilderTest.php @@ -37,6 +37,8 @@ class ShortUrlRedirectionBuilderTest extends TestCase yield ['https://domain.com/foo/bar?some=thing', [], null]; yield ['https://domain.com/foo/bar?some=thing&else', ['else' => null], null]; yield ['https://domain.com/foo/bar?some=thing&foo=bar', ['foo' => 'bar'], null]; + yield ['https://domain.com/foo/bar?some=thing&123=foo', ['123' => 'foo'], null]; + yield ['https://domain.com/foo/bar?some=thing&456=foo', [456 => 'foo'], null]; yield ['https://domain.com/foo/bar?some=overwritten&foo=bar', ['foo' => 'bar', 'some' => 'overwritten'], null]; yield ['https://domain.com/foo/bar?some=overwritten', ['foobar' => 'notrack', 'some' => 'overwritten'], null]; yield ['https://domain.com/foo/bar/something/else-baz?some=thing', [], '/something/else-baz'];