Skip to content

Commit 2174d8e

Browse files
committed
Add check for when a domain already starts with $userId, in which case it should not be prepended again.
1 parent 6b75dd8 commit 2174d8e

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

solid/lib/Controller/GetStorageUrlTrait.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,12 @@ protected function getStorageUrl($userId) {
4444

4545
// @FIXME: $this->getUserSubDomainsEnabled should contain true/false from (?) somewhere
4646
if ($this->config->getUserSubDomainsEnabled()) {
47-
// @FIXME: Check whether we are already on a domain that starts with $userId,
48-
// in which case it should not be prepended again
4947
$url = parse_url($storageUrl);
48+
49+
if (strpos($url['host'], $userId . '.') !== false) {
50+
$url['host'] = str_replace($userId . '.', '', $url['host']);
51+
}
52+
5053
$url['host'] = $userId . '.' . $url['host']; // $storageUrl = $userId . '.' . $storageUrl;
5154
$storageUrl = $this->build_url($url);
5255
}

solid/tests/Unit/Controller/GetStorageUrlTraitTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ public function provideSubDomainsEnabledUrls()
161161
['url' => 'http://example.com/foo', 'userId' => 'alice', 'expected' => 'http://alice.example.com//'],
162162
['url' => 'https://bob.example.com/foo', 'userId' => 'alice', 'expected' => 'https://alice.bob.example.com//'],
163163
['url' => 'http://bob.example.com/foo', 'userId' => 'alice', 'expected' => 'http://alice.bob.example.com//'],
164-
['url' => 'https://bob.example.com/foo', 'userId' => 'bob', 'expected' => 'https://bob.bob.example.com//'],
165-
['url' => 'http://bob.example.com/foo', 'userId' => 'bob', 'expected' => 'http://bob.bob.example.com//'],
164+
['url' => 'https://bob.example.com/foo', 'userId' => 'bob', 'expected' => 'https://bob.example.com//'],
165+
['url' => 'http://bob.example.com/foo', 'userId' => 'bob', 'expected' => 'http://bob.example.com//'],
166166
];
167167
}
168168
}

0 commit comments

Comments
 (0)