Skip to content

Commit 82736a5

Browse files
author
mokimo
committed
fix(clipboard): correctly append attributes
1 parent 386ad6f commit 82736a5

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/clipboard.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export function filterHtmlElements (elem) {
9292

9393
// Keep internal relative links relative (on paste).
9494
if (keepInternalRelativeLinks && child.nodeName === 'A' && child.href) {
95-
const stripInternalHost = child.href.replace(window.location.origin, '')
95+
const stripInternalHost = child.getAttribute('href').replace(window.location.origin, '')
9696
child.setAttribute('href', stripInternalHost)
9797
}
9898

@@ -112,7 +112,7 @@ export function conditionalNodeWrap (child, content) {
112112
nodeName = transformNodeName(nodeName)
113113

114114
if (shouldKeepNode(nodeName, child)) {
115-
var attributes = filterAttributes(nodeName, child)
115+
const attributes = filterAttributes(nodeName, child)
116116

117117
if (nodeName === 'br') return `<${nodeName + attributes}>`
118118

@@ -134,10 +134,11 @@ export function conditionalNodeWrap (child, content) {
134134
return content
135135
}
136136

137+
// returns string of concatenated attributes e.g. 'target="_blank" rel="nofollow" href="/test.com"'
137138
export function filterAttributes (nodeName, node) {
138-
return Array.from(node.attributes).reduce((attributes, {name, value}) => {
139-
if ((allowedElements[nodeName][name]) && value) {
140-
return ` ${name}="${value}"`
139+
return Array.from(node.attributes).reduce((attributes, { name, value }) => {
140+
if (allowedElements[nodeName][name] && value) {
141+
return `${attributes} ${name}="${value}"`
141142
}
142143
return attributes
143144
}, '')

0 commit comments

Comments
 (0)