From 52e1badefb5605f398de699ef685b937955d5274 Mon Sep 17 00:00:00 2001 From: Florian Scholdei Date: Tue, 27 May 2025 09:31:37 +0200 Subject: [PATCH] Fix Permalink generation for line numbers in code view To properly escape branch names containing special characters like `/` (e.g., replaced with `%2F`). This ensures that copied links work correctly even when branch names include special characters. --- gradle/changelog/copy_permalink.yaml | 2 ++ .../src/repos/sources/components/content/SourcecodeViewer.tsx | 2 +- .../sources/components/content/SwitchableMarkdownViewer.tsx | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 gradle/changelog/copy_permalink.yaml diff --git a/gradle/changelog/copy_permalink.yaml b/gradle/changelog/copy_permalink.yaml new file mode 100644 index 0000000000..43c33c11e6 --- /dev/null +++ b/gradle/changelog/copy_permalink.yaml @@ -0,0 +1,2 @@ +- type: fixed + description: Permalink generation for line numbers in code view diff --git a/scm-ui/ui-webapp/src/repos/sources/components/content/SourcecodeViewer.tsx b/scm-ui/ui-webapp/src/repos/sources/components/content/SourcecodeViewer.tsx index 82c2485c9f..e355737600 100644 --- a/scm-ui/ui-webapp/src/repos/sources/components/content/SourcecodeViewer.tsx +++ b/scm-ui/ui-webapp/src/repos/sources/components/content/SourcecodeViewer.tsx @@ -38,7 +38,7 @@ const SourcecodeViewer: FC = ({ file, language }) => { return ; } - const permalink = replaceBranchWithRevision(location.pathname, file.revision); + const permalink = replaceBranchWithRevision(location.pathname, encodeURIComponent(file.revision)); return ; }; diff --git a/scm-ui/ui-webapp/src/repos/sources/components/content/SwitchableMarkdownViewer.tsx b/scm-ui/ui-webapp/src/repos/sources/components/content/SwitchableMarkdownViewer.tsx index 80e45e2a8e..fc3fe9fc85 100644 --- a/scm-ui/ui-webapp/src/repos/sources/components/content/SwitchableMarkdownViewer.tsx +++ b/scm-ui/ui-webapp/src/repos/sources/components/content/SwitchableMarkdownViewer.tsx @@ -47,7 +47,7 @@ const SwitchableMarkdownViewer: FC = ({ file, basePath, repository }) => return ; } - const permalink = replaceBranchWithRevision(location.pathname, file.revision); + const permalink = replaceBranchWithRevision(location.pathname, encodeURIComponent(file.revision)); return (