Repository navigation
Editor: Recognize uppercase URL schemes in link validation. #12103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nimesh-xecurify
wants to merge
6
commits into
WordPress:trunk
Choose a base branch
from
nimesh-xecurify:65417-editor-js-fix
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b7108ee
Editor: Recognize uppercase URL schemes in link validation.
nimesh-xecurify d9be8de
Merge branch 'trunk' into 65417-editor-js-fix
t-hamano e149d2c
Merge remote-tracking branch 'WordPress/trunk' into 65417-editor-js-fix
nimesh-xecurify 1960237
Editor: Accept RFC 3986 scheme characters in link validation.
nimesh-xecurify 6d9143e
Merge branch 'trunk' into 65417-editor-js-fix
t-hamano 49fef0f
Merge branch 'trunk' into 65417-editor-js-fix
t-hamano File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| /* 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 ) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks a bit verbose, since a whole block is added each time a new test case is needed. Instead, how about splitting the cases into two groups, URLs that should get [
'https://example.com',
'HTTPS://example.net',
'Http://example.org',
'chrome-extension://abcdef/options.html',
'web+demo2://example.com',
'#section',
'/page/subpage/'
].forEach( function( url ) {
QUnit.test( 'should not prepend http:// to ' + url, function( assert ) {
jQuery( '#wp-link-url' ).val( url );
wpLink.correctURL();
assert.strictEqual( jQuery( '#wp-link-url' ).val(), url );
} );
} );
[
'example.com',
'example.com:8080/path'
].forEach( function( url ) {
QUnit.test( 'should prepend http:// to ' + url, function( assert ) {
jQuery( '#wp-link-url' ).val( url );
wpLink.correctURL();
assert.strictEqual( jQuery( '#wp-link-url' ).val(), 'http://' + url );
} );
} ); |
||
| 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 scheme containing a hyphen', function( assert ) { | ||
| jQuery( '#wp-link-url' ).val( 'chrome-extension://abcdef/options.html' ); | ||
| wpLink.correctURL(); | ||
| assert.strictEqual( | ||
| jQuery( '#wp-link-url' ).val(), | ||
| 'chrome-extension://abcdef/options.html', | ||
| 'A scheme containing a hyphen should not be modified.' | ||
| ); | ||
| } ); | ||
|
|
||
| QUnit.test( 'should not prepend http:// to a scheme containing a plus sign and digits', function( assert ) { | ||
| jQuery( '#wp-link-url' ).val( 'web+demo2://example.com' ); | ||
| wpLink.correctURL(); | ||
| assert.strictEqual( | ||
| jQuery( '#wp-link-url' ).val(), | ||
| 'web+demo2://example.com', | ||
| 'A scheme containing a plus sign and digits should not be modified.' | ||
| ); | ||
| } ); | ||
|
|
||
| QUnit.test( 'should prepend http:// to a bare host and port', function( assert ) { | ||
| jQuery( '#wp-link-url' ).val( 'example.com:8080/path' ); | ||
| wpLink.correctURL(); | ||
| assert.strictEqual( | ||
| jQuery( '#wp-link-url' ).val(), | ||
| 'http://example.com:8080/path', | ||
| 'A bare host and port is not a scheme, so it 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.' | ||
| ); | ||
| } ); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this regex, a host and port containing a hyphen or a digit (e.g.
my-site:8080/xorsite1:80) no longer getshttp://prepended, although it did before. Unless there's a specific reason for this, I think we should keep the previous behavior. It would also be good to cover this in the unit tests.One way to keep the previous behavior while still recognizing schemes like
chrome-extension://andweb+demo2://is to treat a scheme containing digits,+or-as a scheme only when it's followed by//:my-site:8080/x,site1:80,example.com:8080/pathhttp://prepended (same as before)chrome-extension://abc/o.html,web+demo2://example.comHTTPS://a.com,Http://a.org,mailto:a@b.clocalhost:3000