summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/repository/utils/ref_switcher_utils.js
diff options
context:
space:
mode:
Diffstat (limited to 'app/assets/javascripts/repository/utils/ref_switcher_utils.js')
-rw-r--r--app/assets/javascripts/repository/utils/ref_switcher_utils.js27
1 files changed, 10 insertions, 17 deletions
diff --git a/app/assets/javascripts/repository/utils/ref_switcher_utils.js b/app/assets/javascripts/repository/utils/ref_switcher_utils.js
index bcad4a2c822..c62f7f709c4 100644
--- a/app/assets/javascripts/repository/utils/ref_switcher_utils.js
+++ b/app/assets/javascripts/repository/utils/ref_switcher_utils.js
@@ -16,29 +16,22 @@ const getNamespaceTargetRegex = (ref) => new RegExp(`(/-/(blob|tree))/${ref}/(.*
* @param {string} selectedRef - The selected ref from the ref dropdown.
*/
export function generateRefDestinationPath(projectRootPath, ref, selectedRef) {
- const url = new URL(window.location.href);
- const currentPath = url.pathname;
- let refType = null;
+ const currentPath = window.location.pathname;
+ const encodedHash = '%23';
let namespace = '/-/tree';
let target;
- let actualRef = selectedRef;
-
- const matches = selectedRef.match(/^refs\/(heads|tags)\/(.+)/);
- if (matches) {
- [, refType, actualRef] = matches;
- }
- if (refType) {
- url.searchParams.set('ref_type', refType);
- } else {
- url.searchParams.delete('ref_type');
- }
-
const NAMESPACE_TARGET_REGEX = getNamespaceTargetRegex(ref);
const match = NAMESPACE_TARGET_REGEX.exec(currentPath);
if (match) {
[, namespace, , target] = match;
}
- url.pathname = joinPaths(projectRootPath, namespace, actualRef, target);
- return url.toString();
+ const destinationPath = joinPaths(
+ projectRootPath,
+ namespace,
+ encodeURI(selectedRef).replace(/#/g, encodedHash),
+ target,
+ );
+
+ return `${destinationPath}${window.location.hash}`;
}