Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/js/_enqueues/lib/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
correctURL: function () {
var url = inputs.url.val().trim();

if ( url && correctedURL !== url && ! /^(?:[a-z]+:|#|\?|\.|\/)/.test( url ) ) {
if ( url && correctedURL !== url && ! /^(?:[a-zA-Z]+:|#|\?|\.|\/)/.test( url ) ) {
inputs.url.val( 'http://' + url );
correctedURL = url;
}
Expand Down
2 changes: 1 addition & 1 deletion src/js/_enqueues/vendor/tinymce/plugins/wplink/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@
return;
}

if ( ! /^(?:[a-z]+:|#|\?|\.|\/)/.test( href ) && ! emailRegex.test( href ) ) {
if ( ! /^(?:[a-zA-Z]+:|#|\?|\.|\/)/.test( href ) && ! emailRegex.test( href ) ) {
href = 'http://' + href;
}

Expand Down
4 changes: 4 additions & 0 deletions tests/qunit/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
<body>
<div id="qunit"></div>
<div id="qunit-fixture">
<input id="wp-link-url" type="url" />
<script src="fixtures/customize-header.js"></script>
<script src="fixtures/customize-settings.js"></script>
<script src="fixtures/customize-menus.js"></script>
Expand All @@ -87,6 +88,8 @@
</div>

<!-- Tested files -->
<script>window.wpLinkL10n = window.wpLinkL10n || {};</script>
<script src="../../build/wp-includes/js/wplink.js"></script>
<script src="../../build/wp-admin/js/dashboard.js"></script>
<script src="../../build/wp-admin/js/password-strength-meter.js"></script>
<script src="../../build/wp-admin/js/postbox.js"></script>
Expand Down Expand Up @@ -166,6 +169,7 @@
<script src="wp-admin/js/widgets/test-media-image-widget.js"></script>
<script src="wp-admin/js/widgets/test-media-gallery-widget.js"></script>
<script src="wp-admin/js/widgets/test-media-video-widget.js"></script>
<script src="wp-includes/js/wplink.js"></script>

<!-- Customizer templates for sections -->
<script type="text/html" id="tmpl-customize-section-default">
Expand Down
68 changes: 68 additions & 0 deletions tests/qunit/wp-includes/js/wplink.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/* global wpLink, jQuery */

QUnit.module( 'wpLink.correctURL', {
beforeEach: function() {
// Re-initialize after QUnit resets the fixture, so inputs.url references the live element.
wpLink.init();
}
} );

QUnit.test( 'should not prepend http:// to a lowercase https:// URL', function( assert ) {
jQuery( '#wp-link-url' ).val( 'https://example.com' );
wpLink.correctURL();
assert.strictEqual(
jQuery( '#wp-link-url' ).val(),
'https://example.com',
'A lowercase https:// URL should not be modified.'
);
} );

QUnit.test( 'should not prepend http:// to an uppercase HTTPS:// URL', function( assert ) {
jQuery( '#wp-link-url' ).val( 'HTTPS://example.net' );
wpLink.correctURL();
assert.strictEqual(
jQuery( '#wp-link-url' ).val(),
'HTTPS://example.net',
'An uppercase HTTPS:// URL should not be modified (common on mobile keyboards).'
);
} );

QUnit.test( 'should not prepend http:// to a mixed-case Http:// URL', function( assert ) {
jQuery( '#wp-link-url' ).val( 'Http://example.org' );
wpLink.correctURL();
assert.strictEqual(
jQuery( '#wp-link-url' ).val(),
'Http://example.org',
'A mixed-case Http:// URL should not be modified.'
);
} );

QUnit.test( 'should prepend http:// to a bare domain without a scheme', function( assert ) {
jQuery( '#wp-link-url' ).val( 'example.com' );
wpLink.correctURL();
assert.strictEqual(
jQuery( '#wp-link-url' ).val(),
'http://example.com',
'A bare domain should get http:// prepended.'
);
} );

QUnit.test( 'should not prepend http:// to a fragment URL', function( assert ) {
jQuery( '#wp-link-url' ).val( '#section' );
wpLink.correctURL();
assert.strictEqual(
jQuery( '#wp-link-url' ).val(),
'#section',
'A fragment URL should not be modified.'
);
} );

QUnit.test( 'should not prepend http:// to a root-relative URL', function( assert ) {
jQuery( '#wp-link-url' ).val( '/page/subpage/' );
wpLink.correctURL();
assert.strictEqual(
jQuery( '#wp-link-url' ).val(),
'/page/subpage/',
'A root-relative URL should not be modified.'
);
} );
Loading