|
281 | 281 | * @return {boolean} Is appropriate for changeset link. |
282 | 282 | */ |
283 | 283 | api.isLinkPreviewable = function isLinkPreviewable( element, options ) { |
284 | | - var matchesAllowedUrl, parsedAllowedUrl, args, elementHost; |
| 284 | + var matchesAllowedUrl, matchedAllowedPath, parsedAllowedUrl, args, elementHost; |
285 | 285 |
|
286 | 286 | args = _.extend( {}, { allowAdminAjax: false }, options || {} ); |
287 | 287 |
|
|
298 | 298 | parsedAllowedUrl = document.createElement( 'a' ); |
299 | 299 | matchesAllowedUrl = ! _.isUndefined( _.find( api.settings.url.allowed, function( allowedUrl ) { |
300 | 300 | parsedAllowedUrl.href = allowedUrl; |
301 | | - return parsedAllowedUrl.protocol === element.protocol && parsedAllowedUrl.host.replace( /:(80|443)$/, '' ) === elementHost && 0 === element.pathname.indexOf( parsedAllowedUrl.pathname.replace( /\/$/, '' ) ); |
| 301 | + if ( parsedAllowedUrl.protocol === element.protocol && parsedAllowedUrl.host.replace( /:(80|443)$/, '' ) === elementHost && 0 === element.pathname.indexOf( parsedAllowedUrl.pathname.replace( /\/$/, '' ) ) ) { |
| 302 | + matchedAllowedPath = parsedAllowedUrl.pathname.replace( /\/$/, '' ); |
| 303 | + return true; |
| 304 | + } |
302 | 305 | } ) ); |
303 | 306 | if ( ! matchesAllowedUrl ) { |
304 | 307 | return false; |
|
314 | 317 | return args.allowAdminAjax; |
315 | 318 | } |
316 | 319 |
|
317 | | - // Disallow links to admin, includes, and content. |
318 | | - if ( /\/wp-(admin|includes|content)(\/|$)/.test( element.pathname ) ) { |
| 320 | + // Disallow links to admin, includes, and content, unless the matching allowed URL itself contains such a path. |
| 321 | + if ( /\/wp-(admin|includes|content)(\/|$)/.test( element.pathname.substring( matchedAllowedPath ? matchedAllowedPath.length : 0 ) ) ) { |
319 | 322 | return false; |
320 | 323 | } |
321 | 324 |
|
|
0 commit comments