Merge issue-55-fe (Refs #55)
# Conflicts: # craft/src/styles/editor.css
This commit is contained in:
commit
0ac420a23c
17 files changed
+928
-9
No files matched your search
@@ -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";}</style><script>alert(1)</script>' }, '');
|
||||
expect(html).not.toContain('<script>alert(1)');
|
||||
});
|
||||
});
|
||||
@@ -2,10 +2,12 @@ import React, { CSSProperties } from 'react';
|
||||
import { useNode, Element, UserComponent } from '@craftjs/core';
|
||||
import { Container } from './Container';
|
||||
import { cssPropsToString } from '../../utils/style-helpers';
|
||||
import { escapeAttr } from '../../utils/escape';
|
||||
import { escapeAttr, cssValue } from '../../utils/escape';
|
||||
|
||||
interface BackgroundSectionProps {
|
||||
bgImage?: string;
|
||||
/** CSS background-position (focal point); blank = center. */
|
||||
bgPosition?: string;
|
||||
bgColor?: string;
|
||||
overlayColor?: string;
|
||||
overlayOpacity?: number;
|
||||
@@ -17,6 +19,7 @@ interface BackgroundSectionProps {
|
||||
|
||||
export const BackgroundSection: UserComponent<BackgroundSectionProps> = ({
|
||||
bgImage = '',
|
||||
bgPosition = '',
|
||||
bgColor = '#1e293b',
|
||||
overlayColor = '#000000',
|
||||
overlayOpacity = 0.4,
|
||||
@@ -37,7 +40,7 @@ export const BackgroundSection: UserComponent<BackgroundSectionProps> = ({
|
||||
backgroundColor: bgColor,
|
||||
backgroundImage: bgImage ? `url(${bgImage})` : undefined,
|
||||
backgroundSize: 'cover',
|
||||
backgroundPosition: 'center',
|
||||
backgroundPosition: cssValue(bgPosition) || 'center',
|
||||
...style,
|
||||
}}
|
||||
>
|
||||
@@ -75,6 +78,7 @@ BackgroundSection.craft = {
|
||||
displayName: 'Background Section',
|
||||
props: {
|
||||
bgImage: '',
|
||||
bgPosition: '',
|
||||
bgColor: '#1e293b',
|
||||
overlayColor: '#000000',
|
||||
overlayOpacity: 0.4,
|
||||
@@ -99,7 +103,7 @@ BackgroundSection.craft = {
|
||||
backgroundColor: props.bgColor || '#1e293b',
|
||||
backgroundImage: props.bgImage ? `url(${props.bgImage})` : undefined,
|
||||
backgroundSize: 'cover',
|
||||
backgroundPosition: 'center',
|
||||
backgroundPosition: cssValue(props.bgPosition) || 'center',
|
||||
...props.style,
|
||||
});
|
||||
const overlayStyle = cssPropsToString({
|
||||
|
||||
@@ -48,3 +48,20 @@ describe('HeroSimple.toHtml palette token fallback (Refs #44)', () => {
|
||||
expect(html).not.toContain('var(--wsb-primary)');
|
||||
});
|
||||
});
|
||||
|
||||
describe('HeroSimple.toHtml bgPosition focal point (#55)', () => {
|
||||
const base = { heading: 'Hi', subtitle: 'There', bgType: 'image', bgImage: 'assets/a.jpg' };
|
||||
test('bgPosition is emitted as background-position', () => {
|
||||
const { html } = toHtml({ ...base, bgPosition: 'left top' }, '');
|
||||
expect(html).toContain('background-position:left top');
|
||||
expect(html).not.toContain('background-position:center');
|
||||
});
|
||||
test('blank or missing bgPosition keeps center', () => {
|
||||
expect(toHtml({ ...base, bgPosition: '' }, '').html).toContain('background-position:center');
|
||||
expect(toHtml(base, '').html).toContain('background-position:center');
|
||||
});
|
||||
test('a malicious bgPosition cannot break out of the style attribute', () => {
|
||||
const { html } = toHtml({ ...base, bgPosition: 'left";}</style><script>alert(1)</script>' }, '');
|
||||
expect(html).not.toContain('<script>alert(1)');
|
||||
});
|
||||
});
|
||||
@@ -21,6 +21,8 @@ interface HeroProps {
|
||||
bgGradientTo?: string;
|
||||
bgGradientAngle?: number;
|
||||
bgImage?: string;
|
||||
/** CSS background-position (focal point) for the image background; blank = center. */
|
||||
bgPosition?: string;
|
||||
bgVideo?: string;
|
||||
overlayColor?: string;
|
||||
overlayOpacity?: number;
|
||||
@@ -61,6 +63,7 @@ export const HeroSimple: UserComponent<HeroProps> = ({
|
||||
bgGradientTo = '#764ba2',
|
||||
bgGradientAngle = 135,
|
||||
bgImage = '',
|
||||
bgPosition = '',
|
||||
bgVideo = '',
|
||||
overlayColor = '#000000',
|
||||
overlayOpacity = 0,
|
||||
@@ -97,7 +100,7 @@ export const HeroSimple: UserComponent<HeroProps> = ({
|
||||
background: bgType !== 'image' ? bg : undefined,
|
||||
backgroundImage: bgType === 'image' && bgImage ? `url('${bgImage}')` : undefined,
|
||||
backgroundSize: bgType === 'image' ? 'cover' : undefined,
|
||||
backgroundPosition: bgType === 'image' ? 'center' : undefined,
|
||||
backgroundPosition: bgType === 'image' ? (cssValue(bgPosition) || 'center') : undefined,
|
||||
minHeight: minHeight === '100vh' ? '100vh' : minHeight,
|
||||
display: 'flex',
|
||||
alignItems: justifyMap[verticalAlign] || 'center',
|
||||
@@ -179,6 +182,7 @@ HeroSimple.craft = {
|
||||
bgGradientTo: '#764ba2',
|
||||
bgGradientAngle: 135,
|
||||
bgImage: '',
|
||||
bgPosition: '',
|
||||
bgVideo: '',
|
||||
overlayColor: '#000000',
|
||||
overlayOpacity: 0,
|
||||
@@ -208,7 +212,7 @@ HeroSimple.craft = {
|
||||
background: props.bgType !== 'image' ? bg : undefined,
|
||||
backgroundImage: props.bgType === 'image' && props.bgImage ? `url('${props.bgImage}')` : undefined,
|
||||
backgroundSize: props.bgType === 'image' ? 'cover' : undefined,
|
||||
backgroundPosition: props.bgType === 'image' ? 'center' : undefined,
|
||||
backgroundPosition: props.bgType === 'image' ? (cssValue(props.bgPosition) || 'center') : undefined,
|
||||
minHeight: props.minHeight || '500px',
|
||||
display: 'flex',
|
||||
alignItems: justifyMap[props.verticalAlign || 'center'],
|
||||
|
||||
Reference in new issue
Block a user