Opened 8 years ago
Closed 8 years ago
#36473 closed defect (bug) (fixed)
JavaScript error in theme customizer a specific value of before_widget
Reported by: | martin.krcho | Owned by: | westonruter |
---|---|---|---|
Milestone: | 4.6 | Priority: | normal |
Severity: | normal | Version: | 3.9 |
Component: | Customize | Keywords: | good-first-bug has-patch |
Focuses: | ui | Cc: |
Description
I just came across an issue with the theme customizer. It is failing with the following JavaScript error
Uncaught Error: Syntax error, unrecognized expression: SECTION.widget.widget-%2$s,SECTION.widget.widget-%2$s,SECTION.widget.widget-%2$s,SECTION.widget.widget-%2$s,SECTION.widget.widget-%2$s,SECTION.widget.widget-%2$s
I tracked this issue down to the function buildWidgetSelectors in customize-preview-widgets.min.js, specififcally to this bit of code:
d.before_widget.replace("%1$s", "").replace("%2$s", "")
I am using theme called Bearded that defines the "before_widget" as follows:
<section id="%1$s" class="widget %2$s widget-%2$s">
A possible fix would be to make both of the replace actions mentioned above replace ALL occurencies of the pattern:
d.before_widget.replace(/%1\$s/g, "").replace(/%2\$s/g, "")
Attachments (1)
Change History (8)
#2
@
8 years ago
@westonruter, the code is available on GitHub here:
https://github.com/bonfirelab/bearded/blob/master/library/functions/sidebars.php
#3
@
8 years ago
- Keywords needs-patch good-first-bug added
- Milestone changed from Awaiting Review to Future Release
Thanks. OK, that confirms it. It registers a sidebar with:
'before_widget' => '<section id="%1$s" class="widget %2$s widget-%2$s">',
Only the first instance of %2$s
is getting replaced, so implementing the regex global replacement will do the trick.
The code for
buildWidgetSelectors
has been in place since 3.9.@martin.krcho could you please share the
register_sidebar()
calls that the theme has?You're right that a problem here is that
String.replace()
will only replace the first instance if the replacement arg is a string instead of a regular expression. So changing the pattern it to be a regular expression instead of string should do it, but I want to see how the sidebars are registered to see what is going on.