escape special html characters in addon-serialize
This commit is contained in:
@@ -138,6 +138,16 @@ describe('SerializeAddon', () => {
|
|||||||
assert.equal((output.match(/<div><span>terminal<\/span><\/div>/g) || []).length, 1, output);
|
assert.equal((output.match(/<div><span>terminal<\/span><\/div>/g) || []).length, 1, output);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('basic terminal with html unsafe chars', async () => {
|
||||||
|
await writeP(terminal, ' <script>alert("π = 3.14")</script> ');
|
||||||
|
terminal.select(1, 0, 37);
|
||||||
|
|
||||||
|
const output = serializeAddon.serializeAsHTML({
|
||||||
|
onlySelection: true
|
||||||
|
});
|
||||||
|
assert.equal((output.match(/<div><span><script>alert("&pi; = 3.14")<\/script><\/span><\/div>/g) || []).length, 1, output);
|
||||||
|
});
|
||||||
|
|
||||||
it('cells with bold styling', async () => {
|
it('cells with bold styling', async () => {
|
||||||
await writeP(terminal, ' ' + sgr('1') + 'terminal' + sgr('22') + ' ');
|
await writeP(terminal, ' ' + sgr('1') + 'terminal' + sgr('22') + ' ');
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,14 @@ function constrain(value: number, low: number, high: number): number {
|
|||||||
return Math.max(low, Math.min(value, high));
|
return Math.max(low, Math.min(value, high));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function escapeHtmlChar(c: string): string {
|
||||||
|
switch (c) {
|
||||||
|
case '&': return '&';
|
||||||
|
case '<': return '<';
|
||||||
|
}
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Refine this template class later
|
// TODO: Refine this template class later
|
||||||
abstract class BaseSerializeHandler {
|
abstract class BaseSerializeHandler {
|
||||||
constructor(
|
constructor(
|
||||||
@@ -669,7 +677,7 @@ export class HTMLSerializeHandler extends BaseSerializeHandler {
|
|||||||
if (isEmptyCell) {
|
if (isEmptyCell) {
|
||||||
this._currentRow += ' ';
|
this._currentRow += ' ';
|
||||||
} else {
|
} else {
|
||||||
this._currentRow += cell.getChars();
|
this._currentRow += escapeHtmlChar(cell.getChars());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user