Merge pull request #11134 from Snuffleupagus/addLinkAttributes-assert-url
Ensure that `addLinkAttributes` is always called with a valid `url` parameter
This commit is contained in:
commit
12ff252751
@ -294,6 +294,7 @@ class LinkAnnotationElement extends AnnotationElement {
|
||||
const { data, linkService, } = this;
|
||||
const link = document.createElement('a');
|
||||
|
||||
if (data.url) {
|
||||
addLinkAttributes(link, {
|
||||
url: data.url,
|
||||
target: (data.newWindow ?
|
||||
@ -301,14 +302,11 @@ class LinkAnnotationElement extends AnnotationElement {
|
||||
rel: linkService.externalLinkRel,
|
||||
enabled: linkService.externalLinkEnabled,
|
||||
});
|
||||
|
||||
if (!data.url) {
|
||||
if (data.action) {
|
||||
} else if (data.action) {
|
||||
this._bindNamedAction(link, data.action);
|
||||
} else {
|
||||
this._bindLink(link, data.dest);
|
||||
}
|
||||
}
|
||||
|
||||
this.container.appendChild(link);
|
||||
return this.container;
|
||||
|
@ -354,7 +354,10 @@ const LinkTargetStringMap = [
|
||||
* @param {ExternalLinkParameters} params
|
||||
*/
|
||||
function addLinkAttributes(link, { url, target, rel, enabled = true, } = {}) {
|
||||
const urlNullRemoved = (url ? removeNullCharacters(url) : '');
|
||||
assert(url && typeof url === 'string',
|
||||
'addLinkAttributes: A valid "url" parameter must provided.');
|
||||
|
||||
const urlNullRemoved = removeNullCharacters(url);
|
||||
if (enabled) {
|
||||
link.href = link.title = urlNullRemoved;
|
||||
} else {
|
||||
@ -365,7 +368,6 @@ function addLinkAttributes(link, { url, target, rel, enabled = true, } = {}) {
|
||||
};
|
||||
}
|
||||
|
||||
if (url) {
|
||||
const LinkTargetValues = Object.values(LinkTarget);
|
||||
const targetIndex =
|
||||
LinkTargetValues.includes(target) ? target : LinkTarget.NONE;
|
||||
@ -373,7 +375,6 @@ function addLinkAttributes(link, { url, target, rel, enabled = true, } = {}) {
|
||||
|
||||
link.rel = (typeof rel === 'string' ? rel : DEFAULT_LINK_REL);
|
||||
}
|
||||
}
|
||||
|
||||
// Gets the file name from a given URL.
|
||||
function getFilenameFromUrl(url) {
|
||||
|
Loading…
Reference in New Issue
Block a user