5 recurringUnescapeCSSEncoding,
7 } from '../../lib/sanitize/escape';
9 describe('Escape', () => {
10 describe('escapeForbiddenStyles', () => {
11 it('Should replace absolute styles by relative', () => {
12 expect(escapeForbiddenStyle('position: absolute')).toBe('position: relative');
15 it('Should replace percentage height by unset', () => {
16 expect(escapeForbiddenStyle('height: 100%; min-height: 30% ; max-height: 50%;')).toBe(
17 'height: unset; min-height: unset ; max-height: 50%;'
21 it('Should not replace percent line-height by unset', () => {
22 expect(escapeForbiddenStyle('line-height: 100%;')).toBe('line-height: 100%;');
25 it('Should disable dark styles Color schemes', () => {
26 expect(escapeForbiddenStyle('Color-scheme: light dark;')).toBe('proton-disabled-Color-scheme: light dark;');
29 it('Should disable dark styles media queries', () => {
30 expect(escapeForbiddenStyle('(prefers-color-scheme: dark)')).toBe(
31 '(prefers-proton-disabled-Color-scheme: dark)'
36 describe('recurringUnescapeCSSEncoding', () => {
37 it('should return the expected unescaped CSS string when there is few escapes', () => {
38 const string = `background
39 ur&(https://proton.me/image.jpg);`;
40 const expectedString = `background
41 ur&(https://proton.me/image.jpg);`;
43 expect(recurringUnescapeCSSEncoding(string)).toEqual(expectedString);
46 it('should return an empty string when trying to unescape CSS a content with too much escapes', () => {
47 const string = `background
48 ur&(https://proton.me/image.jpg);`;
49 const expectedString = ``;
51 expect(recurringUnescapeCSSEncoding(string)).toEqual(expectedString);
55 describe('escapeURLinStyle', () => {
56 it('should return an empty string when trying to escape ', () => {
57 const style = `background
58 ur&(https://proton.me/image.jpg);`;
60 expect(escapeURLinStyle(style)).toEqual('');
63 it('should keep the same style', () => {
64 const style = `background
65 ur&(https://proton.me/image.jpg);`;
67 expect(escapeURLinStyle(style)).toEqual(style);
71 describe('unescape', () => {
72 it('should unescape the string', () => {
73 const string = `<Hello>&"<Bye>'`;
74 const expected = `<Hello>&"<Bye>'`;
76 expect(unescape(string)).toEqual(expected);
80 describe('escape', () => {
81 it('should escape the string', () => {
82 const string = `<Hello>&"<Bye>'`;
83 const expected = `<Hello>&"<Bye>'`;
85 expect(escape(string)).toEqual(expected);