-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce prependHTTPS url util (#47648)
* Duplicate existing but for HTTPS * Reuse existing implementation * Rename and add docs for clarity * Add additional test cases Co-authored-by: Marin Atanasov <8436925+tyxla@users.noreply.github.com> * Alphabetise imports --------- Co-authored-by: Marin Atanasov <8436925+tyxla@users.noreply.github.com>
- Loading branch information
Showing
4 changed files
with
159 additions
and
18 deletions.
There are no files selected for viewing
This file contains 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 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 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,33 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { prependHTTP } from './prepend-http'; | ||
|
||
/** | ||
* Prepends "https://" to a url, if it looks like something that is meant to be a TLD. | ||
* | ||
* Note: this will not replace "http://" with "https://". | ||
* | ||
* @param {string} url The URL to test. | ||
* | ||
* @example | ||
* ```js | ||
* const actualURL = prependHTTPS( 'wordpress.org' ); // https://wordpress.org | ||
* ``` | ||
* | ||
* @return {string} The updated URL. | ||
*/ | ||
export function prependHTTPS( url ) { | ||
if ( ! url ) { | ||
return url; | ||
} | ||
|
||
// If url starts with http://, return it as is. | ||
if ( url.startsWith( 'http://' ) ) { | ||
return url; | ||
} | ||
|
||
url = prependHTTP( url ); | ||
|
||
return url.replace( /^http:/, 'https:' ); | ||
} |
This file contains 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
888aecb
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.
Flaky tests detected in 888aecb.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.
🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4326003564
📝 Reported issues:
specs/editor/various/block-hierarchy-navigation.test.js