Skip to content

Commit c58af14

Browse files
authored
Fix truncated href tags (#342)
* add failing test for #338 * quick fix #338 * test full truncated href table output
1 parent 67e853b commit c58af14

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/utils.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,15 @@ function truncate(str, desiredLength, truncateChar) {
193193

194194
let ret = truncateWidthWithAnsi(str, desiredLength);
195195

196-
return ret + truncateChar;
196+
ret += truncateChar;
197+
198+
const hrefTag = '\x1B]8;;\x07';
199+
200+
if (str.includes(hrefTag) && !ret.includes(hrefTag)) {
201+
ret += hrefTag;
202+
}
203+
204+
return ret;
197205
}
198206

199207
function defaultOptions() {

test/issues/338-test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const Table = require('../..');
2+
3+
test('closes href tag on truncated content', () => {
4+
const href = 'http://example.com';
5+
6+
const table = new Table({ colWidths: [15], style: { border: [], head: [] } });
7+
8+
table.push([{ content: 'looooooooooong', href }]);
9+
10+
const expected = [
11+
'┌───────────────┐',
12+
'│ \x1B]8;;http://example.com\x07looooooooooo…\x1B]8;;\x07 │',
13+
'└───────────────┘',
14+
];
15+
16+
expect(table.toString()).toEqual(expected.join('\n'));
17+
});

0 commit comments

Comments
 (0)