-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Fix link color for roles without unfiltered_html capabilities #25411
Closed
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
9d8ab5c
Tell kses not to filter out link color prop
oandregal 8ed853e
Tell kses to allow the values we pass to link color
oandregal f36d75c
Make linter happy
oandregal efb04f6
Provide more linter happiness
oandregal 14d904f
Improve regular expression
oandregal 0ab7205
Add e2e test
oandregal 98d56c2
prettify
oandregal 7b94a13
Pass through if value is a valid CSS color
oandregal a9eb6ea
Make linter happy
oandregal 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 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
7 changes: 7 additions & 0 deletions
7
packages/e2e-tests/specs/editor/various/__snapshots__/link-color.test.js.snap
This file contains 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,7 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Link color control serializes markup properly 1`] = ` | ||
"<!-- wp:paragraph {\\"style\\":{\\"color\\":{\\"link\\":\\"var:preset|color|black\\"}}} --> | ||
<p class=\\"has-link-color\\" style=\\"--wp--style--color--link:var(--wp--preset--color--black)\\">This is <a href=\\"https://wordpress.org/gutenberg\\">Gutenberg</a></p> | ||
<!-- /wp:paragraph -->" | ||
`; |
73 changes: 73 additions & 0 deletions
73
packages/e2e-tests/specs/editor/various/link-color.test.js
This file contains 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,73 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { | ||
clickBlockAppender, | ||
createNewPost, | ||
getEditedPostContent, | ||
pressKeyWithModifier, | ||
publishPost, | ||
} from '@wordpress/e2e-test-utils'; | ||
|
||
describe( 'Link color', () => { | ||
beforeEach( async () => { | ||
await createNewPost(); | ||
} ); | ||
|
||
const waitForAutoFocus = async () => { | ||
await page.waitForFunction( | ||
() => !! document.activeElement.closest( '.block-editor-url-input' ) | ||
); | ||
}; | ||
|
||
it( 'control serializes markup properly', async () => { | ||
// Create a block with some text | ||
await clickBlockAppender(); | ||
await page.keyboard.type( 'This is Gutenberg' ); | ||
|
||
// Select some text | ||
await pressKeyWithModifier( 'shiftAlt', 'ArrowLeft' ); | ||
|
||
// Click on the Link button | ||
await page.click( 'button[aria-label="Link"]' ); | ||
|
||
// Wait for the URL field to auto-focus | ||
await waitForAutoFocus(); | ||
|
||
// Type a URL | ||
await page.keyboard.type( 'https://wordpress.org/gutenberg' ); | ||
|
||
// Submit the link | ||
await page.keyboard.press( 'Enter' ); | ||
|
||
// Simulate the theme has support for link color | ||
await page.evaluate( () => { | ||
wp.data.dispatch( 'core/block-editor' ).updateSettings( { | ||
__experimentalFeatures: { | ||
global: { | ||
color: { link: true }, | ||
}, | ||
}, | ||
} ); | ||
} ); | ||
|
||
// Open color panel | ||
await page.click( | ||
'.block-editor-panel-color-gradient-settings .components-panel__body-toggle' | ||
); | ||
|
||
// Select first color | ||
await page.click( | ||
'.block-editor-panel-color-gradient-settings > .block-editor-color-gradient-control:last-child .components-circular-option-picker__option:first-child' | ||
); | ||
|
||
// Save post. | ||
// We want to test that the link color control data | ||
// persists after kses runs (kses filters out some markup, | ||
// such as CSS variables within the style property). | ||
await publishPost(); | ||
|
||
// Snapshot contains .has-link-color class and inline CSS variable | ||
expect( await getEditedPostContent() ).toMatchSnapshot(); | ||
} ); | ||
} ); |
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.
kses has several checks when filtering post content, this is the relevant function when it comes to filter the
style
attribute: