Repository navigation
Keep backslashes in values synced to post meta - #202
Merged
Merged
Conversation
update_post_meta() runs wp_unslash() on its value, so field values parsed from block attributes lost every backslash on their way into post meta. Slash them first, as content sync already does for add_metadata(). Fixes inline0#200
Contributor
|
Thanks for merging this and for releasing it in 7.7.13. We tested 7.7.13 and backslashes in postMeta storage now survive a save and a resave. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #200.
A field with
postMetastorage lost every backslash on save:a\bwas stored asab,a\\basa\b. The block attribute inpost_contentkept the value, only the meta copy changed.Cause
Storage_Sync::sync_field_value()passes the value parsed from the block straight toupdate_post_meta().update_metadata()expects a slashed value ("For historical reasons both the meta key and the meta value are expected to be slashed", reference) and runswp_unslash()on it first (meta.php on the 7.1 tag). A value that was never slashed loses its backslashes.Fix
wp_slash( $value )beforeupdate_post_meta(), the same wayContent_Syncalready slashes foradd_metadata().wp_slash()walks arrays, so repeater rows are covered. Theupdate_option()branch stays as it is:update_option()does not unslash.I also looked at the other
update_post_meta()calls inincludes/.Page_Syncstores paths throughPage_Paths::encode(), which runswp_normalize_path(), plus UIDs, fingerprints and flags, so no backslashes there. The one free-form value is_blockstudio_page_meta(themetaof a page file), which is only read back as a fallback when the registry has no entry for the post. I left it out to keep this change to the reported bug.Tests
tests/unit/storage/PostMetaSaveTest.phpsaves a post throughwp_insert_post( wp_slash( ... ) ), the way the REST posts controller does, witha\b,a\\b,q"x\y"zandC:\Users\me, checks thatpost_contentkeeps the value and that the meta matches on the first and on a second save, and does the same for a repeater field. All five cases fail before the change (the meta readsab,a\b,q"xy"z,C:Usersme, and['ab', 'c\d']) and pass after.tests/unit/storage/runs green locally (81 tests) against WordPress Playground with the test theme.composer csand PHPStan onstorage-sync.phpare clean. The full suites are left to CI as per AGENTS.md.