FIX: broken URL when username contains subfolder. (#11786)
The bug was mentioned on [meta](https://meta.discourse.org/t/two-bugs-with-usernames-starting-with-subfolder-name/169505) When discourse is installed on `/subfolder` and username is containing subfolder name like for example `subfolderadmin` - user URLs were incorrect. Instead of having `/subfolder/u/subfolderadmin/summary/` we were leading to `/subfolder/uadmin/summary`. The reason for that was incorrect check in `getUrl` helper: ```javascript const found = url.indexOf(baseUri); if (found >= 0 && found < 3) { return url; } return baseUri + url; ``` baseUri is `/subfolder`, url is `/u/subfolderadmin` and indexOf returned position which in the end returned incorrect URL. I think that we should check if the URL starts with baseUri and not if contains baseUri.
This commit is contained in:
parent
a8c5ef7dff
commit
5cbb522c41
|
@ -15,9 +15,9 @@ export default function getURL(url) {
|
|||
return url;
|
||||
}
|
||||
|
||||
const found = url.indexOf(baseUri);
|
||||
const found = url.startsWith(baseUri);
|
||||
|
||||
if (found >= 0 && found < 3) {
|
||||
if (found) {
|
||||
return url;
|
||||
}
|
||||
if (url[0] !== "/") {
|
||||
|
|
|
@ -60,6 +60,12 @@ module("Unit | Utility | get-url", function () {
|
|||
"relative url has subfolder"
|
||||
);
|
||||
|
||||
assert.equal(
|
||||
getURL("/u/forumadmin"),
|
||||
"/forum/u/forumadmin",
|
||||
"relative url has subfolder even if username contains subfolder"
|
||||
);
|
||||
|
||||
assert.equal(
|
||||
getURL(""),
|
||||
"/forum",
|
||||
|
|
Loading…
Reference in New Issue