Closed bobbingwide closed 3 years ago
It would appear that the problem occurs during the reforming of the "content" attribute. In a simple test the source content was
<!-- wp:oik-css/geshi {"lang":"html","text":"oops 2242",
"content":"\u003c!\u002d\u002d wp:template-part
{\u0022slug\u0022:\u0022header\u0022,\u0022theme\u0022:\u0022fizzie\u0022} /\u002d\u002d\u003e"} /-->
the cloned post's content became
<!-- wp:oik-css/geshi {"lang":"html","text":"oops 2242",
"content":"<!-- wp:template-part {\"slug\":\"header\",\"theme\":\"fizzie\"} /-->"} /-->
when loaded by the Block editor in Code editor mode this becomes
<!-- wp:oik-css/geshi /-->
<p>"} /--></p>
It appear that parts of the value of the "content" attribute should be converted to Unicode entities?
In Gutenberg there's a JavaScript function called serializeAttributes
/**
* Given an attributes object, returns a string in the serialized attributes
* format prepared for post content.
*
* @param {Object} attributes Attributes object.
*
* @return {string} Serialized attributes.
*/
export function serializeAttributes( attributes ) {
return (
JSON.stringify( attributes )
// Don't break HTML comments.
.replace( /--/g, '\\u002d\\u002d' )
// Don't break non-standard-compliant tools.
.replace( /</g, '\\u003c' )
.replace( />/g, '\\u003e' )
.replace( /&/g, '\\u0026' )
// Bypass server stripslashes behavior which would unescape stringify's
// escaping of quotation mark.
//
// See: https://developer.wordpress.org/reference/functions/wp_kses_stripslashes/
.replace( /\\"/g, '\\u0022' )
);
}
Looks like we need a PHP equivalent of this function.
function serializeAttributes( $value ) {
$result = str_replace( '\"', '\u0022', $value);
$result = str_replace( '--', '\u002d\u002d', $result);
$result = str_replace( '<', '\u003c', $result);
$result = str_replace( '>', '\u003e', $result);
$result = str_replace( '&', '\u0026', $result);
return $result;
}
I don't know what's to blame at present. I just know it happened. When I cloned my post to https://herbmiller.me/fizzie-an-experimental-full-site-editing-theme/ the
oik-css/geshi
blocks which contained HTML comments for template parts got completely messed up.Workaround
Edit the post manually by copying and pasting the content and updating any IDs in the target.