-
Notifications
You must be signed in to change notification settings - Fork 67
feat: add block defaults for heading theme margin and icon for icon l… #3676
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7cae2eb
feat: add block defaults for heading theme margin and icon for icon l…
Arukuen 07093e7
Merge branch 'develop' into feat/3673/3674-block-defaults
Arukuen 658d0d7
fix: fall back to DEFAULT_SVG when icon is empty
Arukuen 0aa58cc
fix: apply block defaults only on insertion using block variation
Arukuen cfb7275
fix: also apply default attribute to transform
Arukuen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| // This helper is called only by the inserter variation and explicit block | ||
| // transforms. Parsed existing blocks and Design Library blocks do not call it. | ||
| export const getHeadingDefaultAttributes = ( editorSettings = {} ) => { | ||
| const isPost = editorSettings.stackable_current_post_type === 'post' | ||
|
|
||
| return { | ||
| // Posts and non-post editor screens have separate admin defaults. | ||
| useThemeTextMargins: isPost | ||
| ? !! editorSettings.stackable_enable_heading_default_theme_margins_posts | ||
| : !! editorSettings.stackable_enable_heading_default_theme_margins_non_posts, | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| /** | ||
| * External dependencies | ||
| */ | ||
| import { settings } from 'stackable' | ||
|
|
||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import { getHeadingDefaultAttributes } from './util' | ||
|
|
||
| // Scope this variation to direct inserter creation. | ||
| export const getHeadingVariations = ( editorSettings = {} ) => [ | ||
| { | ||
| name: 'default', | ||
| isDefault: true, | ||
| scope: [ 'inserter' ], | ||
| attributes: getHeadingDefaultAttributes( editorSettings ), | ||
| }, | ||
| ] | ||
|
|
||
| export default getHeadingVariations( settings ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| /** | ||
| * External dependencies | ||
| */ | ||
| import { settings } from 'stackable' | ||
|
|
||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import { getIconListDefaultAttributes } from './util' | ||
|
|
||
| // Scope this variation to direct inserter creation. | ||
| export const getIconListVariations = ( editorSettings = {} ) => [ | ||
| { | ||
| name: 'default', | ||
| isDefault: true, | ||
| scope: [ 'inserter' ], | ||
| attributes: getIconListDefaultAttributes( editorSettings ), | ||
| }, | ||
| ] | ||
|
|
||
| export default getIconListVariations( settings ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| .ugb-admin-icon-setting { | ||
| --wp-components-color-accent: var(--stk-skin-dark); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import AdminBaseSetting from '../admin-base-setting' | ||
| import IconControl from '../icon-control' | ||
| import classnames from 'classnames' | ||
|
|
||
| const defaultIcon = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 190 190"><polygon points="173.8,28.4 60.4,141.8 15.7,97.2 5.1,107.8 60.4,163 184.4,39 173.8,28.4"/></svg>' | ||
|
|
||
| const AdminIconSetting = props => { | ||
| return ( | ||
| <AdminBaseSetting | ||
| { ...props } | ||
| className={ classnames( props.className, 'ugb-admin-icon-setting' ) }> | ||
| <IconControl | ||
| label="" | ||
| value={ props.value } | ||
| defaultValue={ defaultIcon } | ||
| onChange={ icon => { | ||
| props.onChange( icon ) | ||
| } } | ||
| allowReset={ false } | ||
| hasPanelModifiedIndicator={ true } | ||
| /> | ||
| { props.children } | ||
| </AdminBaseSetting> | ||
| ) | ||
| } | ||
|
|
||
| AdminIconSetting.defaultProps = { | ||
| value: '', | ||
| onChange: () => {}, | ||
| } | ||
|
|
||
| export default AdminIconSetting |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SVG sanitization may be incomplete for security-critical use.
The current implementation provides basic protection but has gaps that could allow XSS:
Unquoted event handlers: The regex only handles quoted attributes (
on\w+=\s*"..."and'...'), missing unquoted values likeonclick=alert(1).Missing dangerous patterns:
data:URLs (e.g.,xlink:href="data:text/html,<script>...")xlink:hrefandhrefattributes pointing tojavascript:<use>elements referencing external content<animate>,<set>elements that can trigger scriptsError handling:
preg_replacereturnsnullon error; this should be handled.Proposed improvements for more robust sanitization
public function sanitize_svg_setting( $input ) { if ( empty( $input ) ) { return ''; } // Remove scripts, event handlers, foreignObject, iframe, embeds $input = preg_replace( '/<\s*(script|iframe|embed|object|foreignObject)[^>]*>.*?<\s*\/\s*\1\s*>/is', '', $input ); + // Remove potentially dangerous elements + $input = preg_replace( '/<\s*(use|animate|set|animateTransform)[^>]*\/?>/is', '', $input ); $input = preg_replace( '/on\w+\s*=\s*"[^"]*"/i', '', $input ); $input = preg_replace( "/on\w+\s*=\s*'[^']*'/i", '', $input ); + // Handle unquoted event handlers + $input = preg_replace( '/on\w+\s*=\s*[^\s>]+/i', '', $input ); $input = preg_replace( '/javascript:/i', '', $input ); + // Remove data: URLs and xlink:href with dangerous protocols + $input = preg_replace( '/xlink:href\s*=\s*["\'][^"\']*(?:javascript:|data:)[^"\']*["\']/i', '', $input ); + $input = preg_replace( '/href\s*=\s*["\'][^"\']*(?:javascript:|data:)[^"\']*["\']/i', '', $input ); + // Handle preg_replace errors + if ( $input === null ) { + return ''; + } + return $input; }Alternatively, consider using WordPress's built-in
wp_kseswith an SVG-specific allowed tags/attributes list, or a dedicated SVG sanitization library for more comprehensive protection.🤖 Prompt for AI Agents