diff --git a/craft/src/components/layout/BackgroundSection.toHtml.test.ts b/craft/src/components/layout/BackgroundSection.toHtml.test.ts index bdbcb91..ef52c98 100644 --- a/craft/src/components/layout/BackgroundSection.toHtml.test.ts +++ b/craft/src/components/layout/BackgroundSection.toHtml.test.ts @@ -56,3 +56,19 @@ describe('BackgroundSection.toHtml style-value XSS hardening', () => { expect(html).toContain('child'); }); }); + +describe('BackgroundSection.toHtml bgPosition focal point (#55)', () => { + test('bgPosition is emitted as background-position', () => { + const { html } = toHtml({ bgImage: 'assets/a.jpg', bgPosition: 'left top' }, 'child'); + expect(html).toContain('background-position:left top'); + expect(html).not.toContain('background-position:center'); + }); + test('blank or missing bgPosition keeps center', () => { + expect(toHtml({ bgImage: 'assets/a.jpg', bgPosition: '' }, '').html).toContain('background-position:center'); + expect(toHtml({ bgImage: 'assets/a.jpg' }, '').html).toContain('background-position:center'); + }); + test('a malicious bgPosition cannot break out of the style attribute', () => { + const { html } = toHtml({ bgImage: 'x', bgPosition: 'left";}' }, ''); + expect(html).not.toContain('' }, ''); + expect(html).not.toContain('