Make WordPress Core

Opened 11 years ago

Closed 11 years ago

#25315 closed defect (bug) (fixed)

Theme Customizer preview wont load home URL

Reported by: stri8ed's profile stri8ed Owned by: nacin's profile nacin
Milestone: 3.7 Priority: normal
Severity: normal Version: 3.6.1
Component: Customize Keywords: has-patch commit
Focuses: Cc:

Description

In the theme-customizer, clicking on the home link (within the preview iframe), does nothing, unless the home link is followed by a trailing slash.

<a href="http://website.com">Home</a> - will not load. stays on current page and does nothing.

<a href="http://website.com/">Home</a> - loads fine.

This can be very confusing, when you are browsing the theme preview, and you attempt to return to the hompage, only to be unable to do so.

The issue is caused in the "wp-admin/customize.php" file. The array $allowed_urls includes the home_url with a trailing slash, but not without.

Attachments (1)

25315.patch (1.1 KB) - added by SergeyBiryukov 11 years ago.

Download all attachments as: .zip

Change History (11)

#1 @SergeyBiryukov
11 years ago

  • Component changed from Themes to Appearance

#2 @nacin
11 years ago

Looking at this, the JS does a 0 === test_url.indexOf( allowed_url ) check. The issue here being that website.com.notmywebsite.com would match that, unless we look for a trailing slash.

I think we can make this work as long as we check 0 === indexOf for a URL without a trailing slash, but then confirm that the next character is /, #, ?, or that there is no last character (as in this example).

This check isn't here for security, but it doesn't mean we should make it lax.

#3 @SergeyBiryukov
11 years ago

Could not reproduce on a clean install with Twenty Fourteen.

I've changed the link in Twenty Fourteen header to remove the trailing slash, however the URL to be checked in Customizer in the condition mentioned above (tags/3.6.1/wp-admin/js/customize-controls.js#L559) always contains the trailing slash. Tested in Firefox 23, Chrome 29, IE 8, Opera 12.

#4 @SergeyBiryukov
11 years ago

Some more testing: the URL is set in api.Preview (line 34):
tags/3.6.1/wp-includes/js/customize-preview.js#L20.

Unlike $(this).attr('href'), $(this).prop('href') always returns the home URL with a trailing slash.

#5 @stri8ed
11 years ago

The issue can be reproduced by inserting the following link into your header:

<a href="<?php bloginfo('url'); ?>" >Home</a>

Or alternatively, by creating a link in a custom menu, with the URL set to '/'.

This has been tested in Chrome 29, IE10, and FF 18.

#6 @SergeyBiryukov
11 years ago

Still could not reproduce, both options are working for me.

Does this happen with all plugins deactivated and using a default theme?

#7 @stri8ed
11 years ago

Ok, I see what was happening. I had Wordpress installed on a subdirectory (localhost/wordpress). The jquery prop('href') method does not add the trailing slash to such links. See - http://jsfiddle.net/RZMwG/2/

At the same time, the "customize.php" file uses home_url('/') to generate the allowed-url, which appends the trailing slash regardless.

Last edited 11 years ago by stri8ed (previous) (diff)

#8 @SergeyBiryukov
11 years ago

  • Keywords has-patch added; needs-patch removed
  • Milestone changed from Awaiting Review to 3.7

#9 @SergeyBiryukov
11 years ago

  • Keywords commit added

#10 @nacin
11 years ago

  • Owner set to nacin
  • Resolution set to fixed
  • Status changed from new to closed

In 25681:

When determining a frontend, local URL in the theme customizer, match the home URL without a trailing slash.

props SergeyBiryukov.
fixes #25315.

Note: See TracTickets for help on using tickets.