Only remove ? or # if it's part of the url

This commit is contained in:
Rasmus John Pedersen
2018-08-21 17:08:06 +02:00
parent e6597d47e3
commit a725ddae5a
2 changed files with 11 additions and 3 deletions

View File

@@ -43,8 +43,12 @@ angular.module("umbraco").controller("Umbraco.Dialogs.LinkPickerController",
$scope.model.target.url = resp.urls[0];
});
} else if ($scope.target.url.length) {
// a url but no id/udi indicates an external link - trim the url to remove the anchor/qs
$scope.target.url = $scope.model.url.substring(0, $scope.model.url.search(/(#|\?)/));
// a url but no id/udi indicates an external link - trim the url to remove the anchor/qs
// only do the substring if there's a # or a ?
var indexOfAnchor = $scope.model.target.url.search(/(#|\?)/);
if (indexOfAnchor > -1) {
$scope.model.target.url = $scope.model.target.url.substring(0, indexOfAnchor);
}
}
}

View File

@@ -53,7 +53,11 @@ angular.module("umbraco").controller("Umbraco.Overlays.LinkPickerController",
});
} else if ($scope.model.target.url.length) {
// a url but no id/udi indicates an external link - trim the url to remove the anchor/qs
$scope.model.target.url = $scope.model.target.url.substring(0, $scope.model.target.url.search(/(#|\?)/));
// only do the substring if there's a # or a ?
var indexOfAnchor = $scope.model.target.url.search(/(#|\?)/);
if (indexOfAnchor > -1) {
$scope.model.target.url = $scope.model.target.url.substring(0, indexOfAnchor);
}
}
} else if (dialogOptions.anchors) {
$scope.anchorValues = dialogOptions.anchors;