Skip to content

Commit 26b2718

Browse files
Merge pull request #7482 from christianbeeznest/GH-7467
Course: Fix external shortcut links on course homepage - refs #7467
2 parents d0064e4 + 4f42b5a commit 26b2718

2 files changed

Lines changed: 14 additions & 11 deletions

File tree

assets/vue/components/course/ShortCutList.vue

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
:target="props.shortcut.target || '_self'"
3030
:url="resolvedUrl"
3131
class="course-tool__title"
32-
rel="noopener"
32+
rel="noopener noreferrer"
3333
>
3434
{{ shortcut.title }}
3535
</BaseAppLink>
@@ -59,25 +59,29 @@ const props = defineProps({
5959
*/
6060
const resolvedUrl = computed(() => {
6161
const base = props.shortcut.urlOverride || props.shortcut.url || "#"
62-
// If it's absolute or relative, normalize with URL helper and keep it relative.
6362
try {
6463
const u = new URL(base, window.location.origin)
6564
66-
// If URL already has cid (and possibly sid/gid), leave it as-is.
67-
const hasCid = u.searchParams.has("cid")
68-
const hasSid = u.searchParams.has("sid")
65+
// If the link points outside the current origin, do not rewrite it.
66+
const isExternal = u.origin !== window.location.origin
67+
68+
if (isExternal) {
69+
return u.href
70+
}
6971
70-
if (!hasCid && course.value?.id) {
72+
// Same-origin URLs: ensure course/session context when missing.
73+
if (!u.searchParams.has("cid") && course.value?.id) {
7174
u.searchParams.set("cid", course.value.id)
7275
}
73-
if (!hasSid) {
76+
77+
if (!u.searchParams.has("sid")) {
7478
u.searchParams.set("sid", session.value?.id || 0)
7579
}
7680
77-
// Keep it relative (like backend responses)
78-
return u.pathname + (u.search ? `?${u.searchParams.toString()}` : "")
81+
// Keep relative URL for internal navigation and preserve hash.
82+
const qs = u.searchParams.toString()
83+
return u.pathname + (qs ? `?${qs}` : "") + (u.hash || "")
7984
} catch {
80-
// Fallback
8185
return base
8286
}
8387
})

src/CoreBundle/Controller/CourseController.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,6 @@ public function indexJson(
261261
$cid = $course->getId();
262262
$sid = $this->getSessionId() ?: null;
263263

264-
/** @var CShortcut $shortcut */
265264
/** @var CShortcut $shortcut */
266265
foreach ($shortcuts as $shortcut) {
267266
$resourceNode = $shortcut->getShortCutNode();

0 commit comments

Comments
 (0)