Skip to content

Commit 4350fdb

Browse files
ClementVHMarc Cámara
authored and
Marc Cámara
committed
Fixed getLocalizedURL producing duplicate query string (#671)
Happens for non translated routes
1 parent 990f0dd commit 4350fdb

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/Mcamara/LaravelLocalization/LaravelLocalization.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,10 @@ public function getLocalizedURL($locale = null, $url = null, $attributes = [], $
282282
}
283283
} else {
284284
$url = $this->url->to($url);
285-
$url = preg_replace('/'. preg_quote($urlQuery, '/') . '$/', '', $url);
286285
}
287286

287+
$url = preg_replace('/'. preg_quote($urlQuery, '/') . '$/', '', $url);
288+
288289
if ($locale && $translatedRoute = $this->findTranslatedRouteByUrl($url, $attributes, $this->currentLocale)) {
289290
return $this->getURLFromRouteNameTranslated($locale, $translatedRoute, $attributes, $forceDefaultLocation).$urlQuery;
290291
}

tests/LocalizerTests.php

+12
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,18 @@ public function testGetLocalizedURLWithQueryStringAndhideDefaultLocaleInURL()
340340
);
341341
}
342342

343+
public function testGetLocalizedURLWithQueryStringAndNotTranslatedRoute()
344+
{
345+
app()['request'] = $this->createRequest(
346+
$uri = 'en/about?q=2'
347+
);
348+
$laravelLocalization = new \Mcamara\LaravelLocalization\LaravelLocalization();
349+
350+
$this->assertEquals(
351+
$this->test_url . 'en/about?q=2',
352+
$laravelLocalization->getLocalizedURL()
353+
);
354+
}
343355

344356
/**
345357
* @param string $path

0 commit comments

Comments
 (0)