Skip to content

Commit

Permalink
Fix truncated href tags (#342)
Browse files Browse the repository at this point in the history
* add failing test for #338

* quick fix #338

* test full truncated href table output
  • Loading branch information
ItsNickBarry authored May 12, 2024
1 parent 67e853b commit c58af14
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,15 @@ function truncate(str, desiredLength, truncateChar) {

let ret = truncateWidthWithAnsi(str, desiredLength);

return ret + truncateChar;
ret += truncateChar;

const hrefTag = '\x1B]8;;\x07';

if (str.includes(hrefTag) && !ret.includes(hrefTag)) {
ret += hrefTag;
}

return ret;
}

function defaultOptions() {
Expand Down
17 changes: 17 additions & 0 deletions test/issues/338-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const Table = require('../..');

test('closes href tag on truncated content', () => {
const href = 'http://example.com';

const table = new Table({ colWidths: [15], style: { border: [], head: [] } });

table.push([{ content: 'looooooooooong', href }]);

const expected = [
'┌───────────────┐',
'│ \x1B]8;;http://example.com\x07looooooooooo…\x1B]8;;\x07 │',
'└───────────────┘',
];

expect(table.toString()).toEqual(expected.join('\n'));
});

0 comments on commit c58af14

Please sign in to comment.