[wp-trac] [WordPress Trac] #41488: Customize: uncaught JS error with namespaced nav menu fallbacks
WordPress Trac
noreply at wordpress.org
Tue Aug 1 03:02:22 UTC 2017
#41488: Customize: uncaught JS error with namespaced nav menu fallbacks
--------------------------+------------------
Reporter: dlh | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: 4.9
Component: Customize | Version: 4.3
Severity: normal | Resolution:
Keywords: has-patch | Focuses:
--------------------------+------------------
Comment (by westonruter):
@dlh you've found something very interesting!
Given `preg_replace( '#^(.)#', '$1' . json_encode( '\hello\world' ), ' '
)` I would expect it to output:
`"\\hello\\world"`
But instead it outputs:
`"\hello\world"`
Compare this with `str_replace( ' ', ' ' . json_encode( '\hello\world' ),
' ' )`:
`"\\hello\\world"`
So yeah, it seems that not only does the pattern need escaping with PCRE
but also the replacement, even when there are no capture groups!
By using `preg_quote()` on the ''replacement'' value, it also fixes the
issue: [attachment:41488.3.diff].
This seems like a better approach, yes? I wonder how many other instances
of `preg_replace()` have this problem in code I've written.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/41488#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list