Skip to content

Commit c94fb4a

Browse files
committed
- Added test for truncation of long attributes in outerHTML
- Added space consistency for the first attribute - Increased maxlength for the entire outerHTML to 3 times that of the current element
1 parent 9629adb commit c94fb4a

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

lib/core/utils/dq-element.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,11 @@ function truncateAttributes(element, truncatedAttributeSet) {
3232
const openingTagEndIndex = str.indexOf('>');
3333

3434
for (const truncatedAttr of truncatedAttributeSet) {
35-
intermediateAttrString += `${truncatedAttr.substring(0, 20)}... `;
35+
intermediateAttrString += ` ${truncatedAttr.substring(0, 20)}...`;
3636
}
3737

3838
str =
3939
str.substring(0, openingTagEndIndex) +
40-
' ' +
4140
intermediateAttrString +
4241
' ' +
4342
str.substring(openingTagEndIndex);
@@ -74,7 +73,7 @@ function truncateElement(element, maxLength, maxAttributeLength) {
7473
currElementStr = currElementStr.substring(0, maxLength) + '...>';
7574
}
7675

77-
if (currElementStr.length > maxLength) {
76+
if (currElementStr.length > 3 * maxLength) {
7877
const endIndex = currElementStr.indexOf('>');
7978
currElementStr = currElementStr.substring(0, endIndex + 1);
8079
}

test/core/utils/dq-element.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,21 @@ describe('DqElement', () => {
8181
assert.equal(result.source, '<div class="foo" id="target">');
8282
});
8383

84+
it('should truncate large attributes', () => {
85+
const el = document.createElement('div');
86+
let attributeName = 'data-';
87+
for (let i = 0; i < 10000000; i++) {
88+
attributeName += 'foo';
89+
}
90+
el.setAttribute(attributeName, 'bar');
91+
92+
const vNode = new DqElement(el);
93+
assert.equal(
94+
vNode.source,
95+
`<div ${attributeName.substring(0, 20)}... ></div>`
96+
);
97+
});
98+
8499
it('should truncate an element having a large number of attributes', () => {
85100
let customElement = '<div id="target"';
86101
for (let i = 0; i < 10; i++) {

0 commit comments

Comments
 (0)