Skip to content

Serialized code block is only half escaped - #9908

Closed
notnownikki wants to merge 1 commit into
masterfrom
try/why-do-things-not-remain-escaped
Closed

notnownikki wants to merge 1 commit into
masterfrom
try/why-do-things-not-remain-escaped

Conversation

@notnownikki

Copy link
Copy Markdown
Member

Description

While fixing errors related to kses stripping out attributes and tags for non-admin users, I found that the seralized HTML fixture for the code block contains characters that should be htmlentities, but aren't "Fixing" the fixture makes the test fail. Unfortunately, kses does the right thing and converts to entities, so the saved version of the block doesn't match the version the serializer produces.

This branch should pass, shouldn't it?

@notnownikki
notnownikki requested review from aduth and mcsf September 14, 2018 11:49
@notnownikki notnownikki added [Status] In Progress Tracking issues with work in progress [Type] Help Request Help with setup, implementation, or "How do I?" questions. labels Sep 14, 2018
@mcsf

mcsf commented Sep 14, 2018

Copy link
Copy Markdown
Contributor

This should be intentional per work on our element serializer: #5897

@mcsf

mcsf commented Sep 14, 2018

Copy link
Copy Markdown
Contributor

To be a bit more precise: IIRC the serializer aims to strictly follow the spec

the text must not contain the character U+003C LESS-THAN SIGN (<) or an ambiguous ampersand.

/**
* Returns an escaped HTML element value.
*
* @link https://w3c.github.io/html/syntax.html#writing-html-documents-elements
* @link https://w3c.github.io/html/syntax.html#ambiguous-ampersand
*
* "the text must not contain the character U+003C LESS-THAN SIGN (<) or an
* ambiguous ampersand."
*
* @param {string} value Element value.
*
* @return {string} Escaped HTML element value.
*/
function escapeHTML( value ) {
return value.replace( /&/g, '&amp;' ).replace( /</g, '&lt;' );
}

@notnownikki

Copy link
Copy Markdown
Member Author

Ah, gotcha. So when a non-admin user saves a code block, it ends up fully escaped because kses does escaping. It doesn't seem to matter when loading the block back... I guess we're ok with that behaviour?

If so, we'll need to exclude the code block fixtures from the kses test, because we know they're going to be different.

@aduth

aduth commented Sep 14, 2018 •

Copy link
Copy Markdown
Member

Is there a practical impact from the difference here? Considering that the block validation treats them equivalent:

wp.blocks.isEquivalentHTML(
	'return &lt;Button&gt;Click Me!&lt;/Button&gt;;',
	'return &lt;Button>Click Me!&lt;/Button>;'
);
// true

(Exposing isEquivalentHTML requires some hackery)

@notnownikki

Copy link
Copy Markdown
Member Author

There's no difference in actual use. Saving a loading a code block as an author works, so the only real impact here is that a test that makes sure that kses isn't altering things will have to skip the code block, or do something slightly different for the code block.

@aduth

aduth commented Sep 14, 2018

Copy link
Copy Markdown
Member

Previously: #9875

@mcsf

mcsf commented Sep 17, 2018

Copy link
Copy Markdown
Contributor

It seems, from the discussion, that this pull request can be safely closed. Correct?

@notnownikki

Copy link
Copy Markdown
Member Author

Yes, seems so!

@notnownikki
notnownikki deleted the try/why-do-things-not-remain-escaped branch September 17, 2018 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Status] In Progress Tracking issues with work in progress [Type] Help Request Help with setup, implementation, or "How do I?" questions.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants