Skip to content

Commit

Permalink
Fixed getLocalizedURL producing duplicate query string (#671)
Browse files Browse the repository at this point in the history
Happens for non translated routes
  • Loading branch information
ClementVH authored and Marc Cámara committed Oct 17, 2019
1 parent 990f0dd commit 4350fdb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Mcamara/LaravelLocalization/LaravelLocalization.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,10 @@ public function getLocalizedURL($locale = null, $url = null, $attributes = [], $
}
} else {
$url = $this->url->to($url);
$url = preg_replace('/'. preg_quote($urlQuery, '/') . '$/', '', $url);
}

$url = preg_replace('/'. preg_quote($urlQuery, '/') . '$/', '', $url);

if ($locale && $translatedRoute = $this->findTranslatedRouteByUrl($url, $attributes, $this->currentLocale)) {
return $this->getURLFromRouteNameTranslated($locale, $translatedRoute, $attributes, $forceDefaultLocation).$urlQuery;
}
Expand Down
12 changes: 12 additions & 0 deletions tests/LocalizerTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,18 @@ public function testGetLocalizedURLWithQueryStringAndhideDefaultLocaleInURL()
);
}

public function testGetLocalizedURLWithQueryStringAndNotTranslatedRoute()
{
app()['request'] = $this->createRequest(
$uri = 'en/about?q=2'
);
$laravelLocalization = new \Mcamara\LaravelLocalization\LaravelLocalization();

$this->assertEquals(
$this->test_url . 'en/about?q=2',
$laravelLocalization->getLocalizedURL()
);
}

/**
* @param string $path
Expand Down

0 comments on commit 4350fdb

Please sign in to comment.