Add more tests
This commit is contained in:
parent
68e7642827
commit
7e6a84ce19
@ -46,12 +46,12 @@ export class KcSanitizerPolicy {
|
|||||||
public static readonly NAME = new RegExp("[a-zA-Z0-9\\-_\\$]+");
|
public static readonly NAME = new RegExp("[a-zA-Z0-9\\-_\\$]+");
|
||||||
|
|
||||||
public static readonly ALIGN = new RegExp(
|
public static readonly ALIGN = new RegExp(
|
||||||
"center|left|right|justify|char",
|
"\\b(center|left|right|justify|char)\\b",
|
||||||
"i" // Case-insensitive flag
|
"i" // Case-insensitive flag
|
||||||
);
|
);
|
||||||
|
|
||||||
public static readonly VALIGN = new RegExp(
|
public static readonly VALIGN = new RegExp(
|
||||||
"baseline|bottom|middle|top",
|
"\\b(baseline|bottom|middle|top)\\b",
|
||||||
"i" // Case-insensitive flag
|
"i" // Case-insensitive flag
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -75,6 +75,20 @@ describe("KeycloakSanitizerMethod", () => {
|
|||||||
html
|
html
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should handle ordinary texts correctly", () => {
|
||||||
|
let html: string = "";
|
||||||
|
|
||||||
|
html = "Some text";
|
||||||
|
assertResult("Some text", html);
|
||||||
|
|
||||||
|
html = `text with "double quotation"`;
|
||||||
|
assertResult(`text with "double quotation"`, html);
|
||||||
|
|
||||||
|
html = `text with 'single quotation'`;
|
||||||
|
assertResult(`text with 'single quotation'`, html);
|
||||||
|
});
|
||||||
|
|
||||||
it("should handle text styles correctly", () => {
|
it("should handle text styles correctly", () => {
|
||||||
let html: string = "";
|
let html: string = "";
|
||||||
|
|
||||||
@ -90,6 +104,15 @@ describe("KeycloakSanitizerMethod", () => {
|
|||||||
html = `<p align="center"> <b>red text </b></p>`;
|
html = `<p align="center"> <b>red text </b></p>`;
|
||||||
assertResult(`<p align="center"> <b>red text </b></p>`, html);
|
assertResult(`<p align="center"> <b>red text </b></p>`, html);
|
||||||
|
|
||||||
|
html = `<p align="CenTer"> <b> Case-insensitive</b></p>`;
|
||||||
|
assertResult(`<p align="CenTer"> <b> Case-insensitive</b></p>`, html);
|
||||||
|
|
||||||
|
html = `<p align="xyz"> <b>wrong value for align</b></p>`;
|
||||||
|
assertResult(`<p> <b>wrong value for align</b></p>`, html);
|
||||||
|
|
||||||
|
html = `<p align="centercenter"> <b>wrong value for align</b></p>`;
|
||||||
|
assertResult(`<p> <b>wrong value for align</b></p>`, html);
|
||||||
|
|
||||||
html = `<p style="font-size: 20px;">This is a paragraph with larger text.</p>`;
|
html = `<p style="font-size: 20px;">This is a paragraph with larger text.</p>`;
|
||||||
assertResult(
|
assertResult(
|
||||||
`<p style="font-size: 20px;">This is a paragraph with larger text.</p>`,
|
`<p style="font-size: 20px;">This is a paragraph with larger text.</p>`,
|
||||||
@ -100,13 +123,23 @@ describe("KeycloakSanitizerMethod", () => {
|
|||||||
assertResult(`<h3> או נושא שתבחר</h3>`, html);
|
assertResult(`<h3> או נושא שתבחר</h3>`, html);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should handle styles correctly", () => {
|
||||||
|
let html = "";
|
||||||
|
html = `<table border="5"> </table>`;
|
||||||
|
assertResult(`<table border="5"> </table>`, html);
|
||||||
|
|
||||||
|
html = `<table border="xyz"> </table>`;
|
||||||
|
assertResult(`<table> </table>`, html);
|
||||||
|
|
||||||
|
html = `<font color = "red"> Content </font>`;
|
||||||
|
assertResult(`<font color="red"> Content </font>`, html);
|
||||||
|
});
|
||||||
|
|
||||||
function assertResult(expectedResult: string | null, html: string | null): void {
|
function assertResult(expectedResult: string | null, html: string | null): void {
|
||||||
if (expectedResult === null) {
|
if (expectedResult === null) {
|
||||||
expect(KcSanitizer.sanitize(html)).toThrow("Cannot escape null value.");
|
expect(KcSanitizer.sanitize(html)).toThrow("Cannot escape null value.");
|
||||||
} else {
|
} else {
|
||||||
const result = KcSanitizer.sanitize(html);
|
const result = KcSanitizer.sanitize(html);
|
||||||
console.log("expectedResult is ", expectedResult);
|
|
||||||
console.log("Result is ", result);
|
|
||||||
expect(result).toBe(expectedResult);
|
expect(result).toBe(expectedResult);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user