Skip to content

Commit 29655fe

Browse files
tahmidsadikgajus
authored andcommitted
feat: whitelist control chars to print hyperlinks in terminal, addresses issue #82 (#93)
1 parent e90e5d1 commit 29655fe

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/validateTableData.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export default (rows) => {
3636

3737
for (const cell of cells) {
3838
// eslint-disable-next-line no-control-regex
39-
if (/[\u0001-\u0009\u000B-\u001A]/.test(cell)) {
39+
if (/[\u0001-\u0006\u0008-\u0009\u000B-\u001A]/.test(cell)) {
4040
throw new Error('Table data must not contain control characters.');
4141
}
4242
}

test/validateTableData.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,33 @@ describe('validateTableData', () => {
5858
});
5959
});
6060

61+
context('cell data contains hyperlinks', () => {
62+
const OSC = '\u001B]';
63+
const BEL = '\u0007';
64+
const SEP = ';';
65+
const url = 'https://example.com';
66+
const text = 'This is a link to example.com';
67+
68+
const link = [
69+
OSC,
70+
'8',
71+
SEP,
72+
SEP,
73+
url,
74+
BEL,
75+
text,
76+
OSC,
77+
'8',
78+
SEP,
79+
SEP,
80+
BEL
81+
].join('');
82+
83+
it('does not throw', () => {
84+
validateTableData([[link]]);
85+
});
86+
});
87+
6188
context('rows have inconsistent number of cells', () => {
6289
it('throws an error', () => {
6390
expect(() => {

0 commit comments

Comments
 (0)