-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: escape pipe operators in table values (#286)
- Loading branch information
1 parent
152711d
commit 8782713
Showing
4 changed files
with
68 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { render } from '@asyncapi/generator-react-sdk'; | ||
|
||
import { Table, TableRow } from '../../components/common'; | ||
|
||
describe('Table', () => { | ||
it('should escape pipe operators in cell values', () => { | ||
const headers = ['Name', 'Type', 'Description', 'Value', 'Constraints', 'Notes']; | ||
|
||
const data = [[ | ||
'(root)', | ||
'string', | ||
'-', | ||
'allowed (`"foo|bar|baz"`)', | ||
'pattern (`/foo\\|bar/`)', | ||
'-', | ||
]]; | ||
const rowRenderer = (it) => it; | ||
|
||
const expected = ` | ||
| Name | Type | Description | Value | Constraints | Notes | | ||
|---|---|---|---|---|---| | ||
| (root) | string | - | allowed (\`"foo\\|bar\\|baz"\`) | pattern (\`/foo\\\\|bar/\`) | - | | ||
`; | ||
|
||
const result = render(<Table headers={headers} rowRenderer={rowRenderer} data={data} />); | ||
expect(result.trim()).toEqual(expected.trim()); | ||
}); | ||
}); | ||
|
||
describe('Table Row', () => { | ||
it('should escape pipe operators in row values', () => { | ||
const rowRenderer = () => [ | ||
'(root)', | ||
'string', | ||
'-', | ||
'allowed (`"foo|bar|baz"`)', | ||
'pattern (`/foo\\|bar/`)', | ||
'-', | ||
]; | ||
|
||
const expected = '| (root) | string | - | allowed (`"foo\\|bar\\|baz"`) | pattern (`/foo\\\\|bar/`) | - |'; | ||
|
||
const result = render(<TableRow rowRenderer={rowRenderer} />); | ||
expect(result.trim()).toEqual(expected.trim()); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters