Skip to content

Commit

Permalink
Whitelists control chars to print hyperlinks in terminal, addresses i…
Browse files Browse the repository at this point in the history
…ssue gajus#82
  • Loading branch information
tahmidsadik committed May 9, 2019
1 parent e90e5d1 commit 1226e8d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/validateTableData.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default (rows) => {

for (const cell of cells) {
// eslint-disable-next-line no-control-regex
if (/[\u0001-\u0009\u000B-\u001A]/.test(cell)) {
if (/[\u0001-\u0006\u0008-\u0009\u000B-\u001A]/.test(cell)) {
throw new Error('Table data must not contain control characters.');
}
}
Expand Down
27 changes: 27 additions & 0 deletions test/validateTableData.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,33 @@ describe('validateTableData', () => {
});
});

context('cell data contains hyperlinks', () => {
const OSC = '\u001B]';
const BEL = '\u0007';
const SEP = ';';
const url = 'https://example.com';
const text = 'This is a link to example.com';

const link = [
OSC,
'8',
SEP,
SEP,
url,
BEL,
text,
OSC,
'8',
SEP,
SEP,
BEL
].join('');

it('does not throw', () => {
validateTableData([[link]]);
});
});

context('rows have inconsistent number of cells', () => {
it('throws an error', () => {
expect(() => {
Expand Down

0 comments on commit 1226e8d

Please sign in to comment.