Merged in feature/81-dev-dev01 (pull request #5)
auto-patch 81-dev-dev01-2023-12-05T22_45_26 * auto-patch 81-dev-dev01-2023-12-05T22_45_26
This commit is contained in:
265
wp/wp-includes/js/dist/url.js
vendored
265
wp/wp-includes/js/dist/url.js
vendored
@@ -20,6 +20,11 @@ var characterMap = {
|
||||
"Ầ": "A",
|
||||
"Ằ": "A",
|
||||
"Ȃ": "A",
|
||||
"Ả": "A",
|
||||
"Ạ": "A",
|
||||
"Ẩ": "A",
|
||||
"Ẫ": "A",
|
||||
"Ậ": "A",
|
||||
"Ç": "C",
|
||||
"Ḉ": "C",
|
||||
"È": "E",
|
||||
@@ -32,12 +37,20 @@ var characterMap = {
|
||||
"Ḕ": "E",
|
||||
"Ḝ": "E",
|
||||
"Ȇ": "E",
|
||||
"Ẻ": "E",
|
||||
"Ẽ": "E",
|
||||
"Ẹ": "E",
|
||||
"Ể": "E",
|
||||
"Ễ": "E",
|
||||
"Ệ": "E",
|
||||
"Ì": "I",
|
||||
"Í": "I",
|
||||
"Î": "I",
|
||||
"Ï": "I",
|
||||
"Ḯ": "I",
|
||||
"Ȋ": "I",
|
||||
"Ỉ": "I",
|
||||
"Ị": "I",
|
||||
"Ð": "D",
|
||||
"Ñ": "N",
|
||||
"Ò": "O",
|
||||
@@ -50,10 +63,25 @@ var characterMap = {
|
||||
"Ṍ": "O",
|
||||
"Ṓ": "O",
|
||||
"Ȏ": "O",
|
||||
"Ỏ": "O",
|
||||
"Ọ": "O",
|
||||
"Ổ": "O",
|
||||
"Ỗ": "O",
|
||||
"Ộ": "O",
|
||||
"Ờ": "O",
|
||||
"Ở": "O",
|
||||
"Ỡ": "O",
|
||||
"Ớ": "O",
|
||||
"Ợ": "O",
|
||||
"Ù": "U",
|
||||
"Ú": "U",
|
||||
"Û": "U",
|
||||
"Ü": "U",
|
||||
"Ủ": "U",
|
||||
"Ụ": "U",
|
||||
"Ử": "U",
|
||||
"Ữ": "U",
|
||||
"Ự": "U",
|
||||
"Ý": "Y",
|
||||
"à": "a",
|
||||
"á": "a",
|
||||
@@ -70,6 +98,11 @@ var characterMap = {
|
||||
"ầ": "a",
|
||||
"ằ": "a",
|
||||
"ȃ": "a",
|
||||
"ả": "a",
|
||||
"ạ": "a",
|
||||
"ẩ": "a",
|
||||
"ẫ": "a",
|
||||
"ậ": "a",
|
||||
"ç": "c",
|
||||
"ḉ": "c",
|
||||
"è": "e",
|
||||
@@ -82,12 +115,20 @@ var characterMap = {
|
||||
"ḕ": "e",
|
||||
"ḝ": "e",
|
||||
"ȇ": "e",
|
||||
"ẻ": "e",
|
||||
"ẽ": "e",
|
||||
"ẹ": "e",
|
||||
"ể": "e",
|
||||
"ễ": "e",
|
||||
"ệ": "e",
|
||||
"ì": "i",
|
||||
"í": "i",
|
||||
"î": "i",
|
||||
"ï": "i",
|
||||
"ḯ": "i",
|
||||
"ȋ": "i",
|
||||
"ỉ": "i",
|
||||
"ị": "i",
|
||||
"ð": "d",
|
||||
"ñ": "n",
|
||||
"ò": "o",
|
||||
@@ -100,10 +141,25 @@ var characterMap = {
|
||||
"ṍ": "o",
|
||||
"ṓ": "o",
|
||||
"ȏ": "o",
|
||||
"ỏ": "o",
|
||||
"ọ": "o",
|
||||
"ổ": "o",
|
||||
"ỗ": "o",
|
||||
"ộ": "o",
|
||||
"ờ": "o",
|
||||
"ở": "o",
|
||||
"ỡ": "o",
|
||||
"ớ": "o",
|
||||
"ợ": "o",
|
||||
"ù": "u",
|
||||
"ú": "u",
|
||||
"û": "u",
|
||||
"ü": "u",
|
||||
"ủ": "u",
|
||||
"ụ": "u",
|
||||
"ử": "u",
|
||||
"ữ": "u",
|
||||
"ự": "u",
|
||||
"ý": "y",
|
||||
"ÿ": "y",
|
||||
"Ā": "A",
|
||||
@@ -225,7 +281,6 @@ var characterMap = {
|
||||
"ş": "s",
|
||||
"Š": "S",
|
||||
"š": "s",
|
||||
"ß": "ss",
|
||||
"Ţ": "T",
|
||||
"ţ": "t",
|
||||
"ț": "t",
|
||||
@@ -419,7 +474,7 @@ function matcher(match) {
|
||||
return characterMap[match];
|
||||
}
|
||||
|
||||
var removeAccents = function(string) {
|
||||
var removeAccents = function(string) {
|
||||
return string.replace(allAccents, matcher);
|
||||
};
|
||||
|
||||
@@ -511,33 +566,33 @@ __webpack_require__.r(__webpack_exports__);
|
||||
|
||||
// EXPORTS
|
||||
__webpack_require__.d(__webpack_exports__, {
|
||||
"addQueryArgs": function() { return /* reexport */ addQueryArgs; },
|
||||
"buildQueryString": function() { return /* reexport */ buildQueryString; },
|
||||
"cleanForSlug": function() { return /* reexport */ cleanForSlug; },
|
||||
"filterURLForDisplay": function() { return /* reexport */ filterURLForDisplay; },
|
||||
"getAuthority": function() { return /* reexport */ getAuthority; },
|
||||
"getFilename": function() { return /* reexport */ getFilename; },
|
||||
"getFragment": function() { return /* reexport */ getFragment; },
|
||||
"getPath": function() { return /* reexport */ getPath; },
|
||||
"getPathAndQueryString": function() { return /* reexport */ getPathAndQueryString; },
|
||||
"getProtocol": function() { return /* reexport */ getProtocol; },
|
||||
"getQueryArg": function() { return /* reexport */ getQueryArg; },
|
||||
"getQueryArgs": function() { return /* reexport */ getQueryArgs; },
|
||||
"getQueryString": function() { return /* reexport */ getQueryString; },
|
||||
"hasQueryArg": function() { return /* reexport */ hasQueryArg; },
|
||||
"isEmail": function() { return /* reexport */ isEmail; },
|
||||
"isURL": function() { return /* reexport */ isURL; },
|
||||
"isValidAuthority": function() { return /* reexport */ isValidAuthority; },
|
||||
"isValidFragment": function() { return /* reexport */ isValidFragment; },
|
||||
"isValidPath": function() { return /* reexport */ isValidPath; },
|
||||
"isValidProtocol": function() { return /* reexport */ isValidProtocol; },
|
||||
"isValidQueryString": function() { return /* reexport */ isValidQueryString; },
|
||||
"normalizePath": function() { return /* reexport */ normalizePath; },
|
||||
"prependHTTP": function() { return /* reexport */ prependHTTP; },
|
||||
"prependHTTPS": function() { return /* reexport */ prependHTTPS; },
|
||||
"removeQueryArgs": function() { return /* reexport */ removeQueryArgs; },
|
||||
"safeDecodeURI": function() { return /* reexport */ safeDecodeURI; },
|
||||
"safeDecodeURIComponent": function() { return /* reexport */ safeDecodeURIComponent; }
|
||||
addQueryArgs: function() { return /* reexport */ addQueryArgs; },
|
||||
buildQueryString: function() { return /* reexport */ buildQueryString; },
|
||||
cleanForSlug: function() { return /* reexport */ cleanForSlug; },
|
||||
filterURLForDisplay: function() { return /* reexport */ filterURLForDisplay; },
|
||||
getAuthority: function() { return /* reexport */ getAuthority; },
|
||||
getFilename: function() { return /* reexport */ getFilename; },
|
||||
getFragment: function() { return /* reexport */ getFragment; },
|
||||
getPath: function() { return /* reexport */ getPath; },
|
||||
getPathAndQueryString: function() { return /* reexport */ getPathAndQueryString; },
|
||||
getProtocol: function() { return /* reexport */ getProtocol; },
|
||||
getQueryArg: function() { return /* reexport */ getQueryArg; },
|
||||
getQueryArgs: function() { return /* reexport */ getQueryArgs; },
|
||||
getQueryString: function() { return /* reexport */ getQueryString; },
|
||||
hasQueryArg: function() { return /* reexport */ hasQueryArg; },
|
||||
isEmail: function() { return /* reexport */ isEmail; },
|
||||
isURL: function() { return /* reexport */ isURL; },
|
||||
isValidAuthority: function() { return /* reexport */ isValidAuthority; },
|
||||
isValidFragment: function() { return /* reexport */ isValidFragment; },
|
||||
isValidPath: function() { return /* reexport */ isValidPath; },
|
||||
isValidProtocol: function() { return /* reexport */ isValidProtocol; },
|
||||
isValidQueryString: function() { return /* reexport */ isValidQueryString; },
|
||||
normalizePath: function() { return /* reexport */ normalizePath; },
|
||||
prependHTTP: function() { return /* reexport */ prependHTTP; },
|
||||
prependHTTPS: function() { return /* reexport */ prependHTTPS; },
|
||||
removeQueryArgs: function() { return /* reexport */ removeQueryArgs; },
|
||||
safeDecodeURI: function() { return /* reexport */ safeDecodeURI; },
|
||||
safeDecodeURIComponent: function() { return /* reexport */ safeDecodeURIComponent; }
|
||||
});
|
||||
|
||||
;// CONCATENATED MODULE: ./node_modules/@wordpress/url/build-module/is-url.js
|
||||
@@ -569,6 +624,7 @@ function isURL(url) {
|
||||
|
||||
;// CONCATENATED MODULE: ./node_modules/@wordpress/url/build-module/is-email.js
|
||||
const EMAIL_REGEXP = /^(mailto:)?[a-z0-9._%+-]+@[a-z0-9][a-z0-9.-]*\.[a-z]{2,63}$/i;
|
||||
|
||||
/**
|
||||
* Determines whether the given string looks like an email.
|
||||
*
|
||||
@@ -581,7 +637,6 @@ const EMAIL_REGEXP = /^(mailto:)?[a-z0-9._%+-]+@[a-z0-9][a-z0-9.-]*\.[a-z]{2,63}
|
||||
*
|
||||
* @return {boolean} Whether or not it looks like an email.
|
||||
*/
|
||||
|
||||
function isEmail(email) {
|
||||
return EMAIL_REGEXP.test(email);
|
||||
}
|
||||
@@ -602,7 +657,6 @@ function isEmail(email) {
|
||||
*/
|
||||
function getProtocol(url) {
|
||||
const matches = /^([^\s:]+:)/.exec(url);
|
||||
|
||||
if (matches) {
|
||||
return matches[1];
|
||||
}
|
||||
@@ -626,7 +680,6 @@ function isValidProtocol(protocol) {
|
||||
if (!protocol) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return /^[a-z\-.\+]+[0-9]*:$/i.test(protocol);
|
||||
}
|
||||
|
||||
@@ -646,7 +699,6 @@ function isValidProtocol(protocol) {
|
||||
*/
|
||||
function getAuthority(url) {
|
||||
const matches = /^[^\/\s:]+:(?:\/\/)?\/?([^\/\s#?]+)[\/#?]{0,1}\S*$/.exec(url);
|
||||
|
||||
if (matches) {
|
||||
return matches[1];
|
||||
}
|
||||
@@ -670,7 +722,6 @@ function isValidAuthority(authority) {
|
||||
if (!authority) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return /^[^\s#?]+$/.test(authority);
|
||||
}
|
||||
|
||||
@@ -690,7 +741,6 @@ function isValidAuthority(authority) {
|
||||
*/
|
||||
function getPath(url) {
|
||||
const matches = /^[^\/\s:]+:(?:\/\/)?[^\/\s#?]+[\/]([^\s#?]+)[#?]{0,1}\S*$/.exec(url);
|
||||
|
||||
if (matches) {
|
||||
return matches[1];
|
||||
}
|
||||
@@ -714,7 +764,6 @@ function isValidPath(path) {
|
||||
if (!path) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return /^[^\s#?]+$/.test(path);
|
||||
}
|
||||
|
||||
@@ -733,11 +782,9 @@ function isValidPath(path) {
|
||||
*/
|
||||
function getQueryString(url) {
|
||||
let query;
|
||||
|
||||
try {
|
||||
query = new URL(url, 'http://example.com').search.substring(1);
|
||||
} catch (error) {}
|
||||
|
||||
if (query) {
|
||||
return query;
|
||||
}
|
||||
@@ -772,18 +819,16 @@ function buildQueryString(data) {
|
||||
let string = '';
|
||||
const stack = Object.entries(data);
|
||||
let pair;
|
||||
|
||||
while (pair = stack.shift()) {
|
||||
let [key, value] = pair; // Support building deeply nested data, from array or object values.
|
||||
let [key, value] = pair;
|
||||
|
||||
// Support building deeply nested data, from array or object values.
|
||||
const hasNestedData = Array.isArray(value) || value && value.constructor === Object;
|
||||
|
||||
if (hasNestedData) {
|
||||
// Push array or object values onto the stack as composed of their
|
||||
// original key and nested index or key, retaining order by a
|
||||
// combination of Array#reverse and Array#unshift onto the stack.
|
||||
const valuePairs = Object.entries(value).reverse();
|
||||
|
||||
for (const [member, memberValue] of valuePairs) {
|
||||
stack.unshift([`${key}[${member}]`, memberValue]);
|
||||
}
|
||||
@@ -792,14 +837,13 @@ function buildQueryString(data) {
|
||||
if (value === null) {
|
||||
value = '';
|
||||
}
|
||||
|
||||
string += '&' + [key, value].map(encodeURIComponent).join('=');
|
||||
}
|
||||
} // Loop will concatenate with leading `&`, but it's only expected for all
|
||||
}
|
||||
|
||||
// Loop will concatenate with leading `&`, but it's only expected for all
|
||||
// but the first query parameter. This strips the leading `&`, while still
|
||||
// accounting for the case that the string may in-fact be empty.
|
||||
|
||||
|
||||
return string.substr(1);
|
||||
}
|
||||
|
||||
@@ -821,7 +865,6 @@ function isValidQueryString(queryString) {
|
||||
if (!queryString) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return /^[^\s#?\/]+$/.test(queryString);
|
||||
}
|
||||
|
||||
@@ -830,6 +873,7 @@ function isValidQueryString(queryString) {
|
||||
* Internal dependencies
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Returns the path part and query string part of the URL.
|
||||
*
|
||||
@@ -843,7 +887,6 @@ function isValidQueryString(queryString) {
|
||||
*
|
||||
* @return {string} The path part and query string part of the URL.
|
||||
*/
|
||||
|
||||
function getPathAndQueryString(url) {
|
||||
const path = getPath(url);
|
||||
const queryString = getQueryString(url);
|
||||
@@ -869,7 +912,6 @@ function getPathAndQueryString(url) {
|
||||
*/
|
||||
function getFragment(url) {
|
||||
const matches = /^\S+?(#[^\s\?]*)/.exec(url);
|
||||
|
||||
if (matches) {
|
||||
return matches[1];
|
||||
}
|
||||
@@ -893,7 +935,6 @@ function isValidFragment(fragment) {
|
||||
if (!fragment) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return /^#[^\s#?\/]*$/.test(fragment);
|
||||
}
|
||||
|
||||
@@ -920,6 +961,7 @@ function safeDecodeURIComponent(uriComponent) {
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/** @typedef {import('./get-query-arg').QueryArgParsed} QueryArgParsed */
|
||||
|
||||
/**
|
||||
@@ -934,40 +976,40 @@ function safeDecodeURIComponent(uriComponent) {
|
||||
* @param {string[]} path Path segment at which to set value.
|
||||
* @param {*} value Value to set.
|
||||
*/
|
||||
|
||||
function setPath(object, path, value) {
|
||||
const length = path.length;
|
||||
const lastIndex = length - 1;
|
||||
|
||||
for (let i = 0; i < length; i++) {
|
||||
let key = path[i];
|
||||
|
||||
if (!key && Array.isArray(object)) {
|
||||
// If key is empty string and next value is array, derive key from
|
||||
// the current length of the array.
|
||||
key = object.length.toString();
|
||||
}
|
||||
key = ['__proto__', 'constructor', 'prototype'].includes(key) ? key.toUpperCase() : key;
|
||||
|
||||
key = ['__proto__', 'constructor', 'prototype'].includes(key) ? key.toUpperCase() : key; // If the next key in the path is numeric (or empty string), it will be
|
||||
// If the next key in the path is numeric (or empty string), it will be
|
||||
// created as an array. Otherwise, it will be created as an object.
|
||||
|
||||
const isNextKeyArrayIndex = !isNaN(Number(path[i + 1]));
|
||||
object[key] = i === lastIndex ? // If at end of path, assign the intended value.
|
||||
value : // Otherwise, advance to the next object in the path, creating
|
||||
object[key] = i === lastIndex ?
|
||||
// If at end of path, assign the intended value.
|
||||
value :
|
||||
// Otherwise, advance to the next object in the path, creating
|
||||
// it if it does not yet exist.
|
||||
object[key] || (isNextKeyArrayIndex ? [] : {});
|
||||
|
||||
if (Array.isArray(object[key]) && !isNextKeyArrayIndex) {
|
||||
// If we current key is non-numeric, but the next value is an
|
||||
// array, coerce the value to an object.
|
||||
object[key] = { ...object[key]
|
||||
object[key] = {
|
||||
...object[key]
|
||||
};
|
||||
} // Update working reference object to the next in the path.
|
||||
|
||||
}
|
||||
|
||||
// Update working reference object to the next in the path.
|
||||
object = object[key];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an object of query arguments of the given URL. If the given URL is
|
||||
* invalid or has no querystring, an empty object is returned.
|
||||
@@ -982,23 +1024,21 @@ function setPath(object, path, value) {
|
||||
*
|
||||
* @return {QueryArgs} Query args object.
|
||||
*/
|
||||
|
||||
|
||||
function getQueryArgs(url) {
|
||||
return (getQueryString(url) || '' // Normalize space encoding, accounting for PHP URL encoding
|
||||
return (getQueryString(url) || ''
|
||||
// Normalize space encoding, accounting for PHP URL encoding
|
||||
// corresponding to `application/x-www-form-urlencoded`.
|
||||
//
|
||||
// See: https://tools.ietf.org/html/rfc1866#section-8.2.1
|
||||
).replace(/\+/g, '%20').split('&').reduce((accumulator, keyValue) => {
|
||||
const [key, value = ''] = keyValue.split('=') // Filtering avoids decoding as `undefined` for value, where
|
||||
const [key, value = ''] = keyValue.split('=')
|
||||
// Filtering avoids decoding as `undefined` for value, where
|
||||
// default is restored in destructuring assignment.
|
||||
.filter(Boolean).map(safeDecodeURIComponent);
|
||||
|
||||
if (key) {
|
||||
const segments = key.replace(/\]/g, '').split('[');
|
||||
setPath(accumulator, segments, value);
|
||||
}
|
||||
|
||||
return accumulator;
|
||||
}, Object.create(null));
|
||||
}
|
||||
@@ -1009,6 +1049,7 @@ function getQueryArgs(url) {
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Appends arguments as querystring to the provided URL. If the URL already
|
||||
* includes query arguments, the arguments are merged with (and take precedent
|
||||
@@ -1025,24 +1066,22 @@ function getQueryArgs(url) {
|
||||
*
|
||||
* @return {string} URL with arguments applied.
|
||||
*/
|
||||
|
||||
function addQueryArgs(url = '', args) {
|
||||
// If no arguments are to be appended, return original URL.
|
||||
if (!args || !Object.keys(args).length) {
|
||||
return url;
|
||||
}
|
||||
let baseUrl = url;
|
||||
|
||||
let baseUrl = url; // Determine whether URL already had query arguments.
|
||||
|
||||
// Determine whether URL already had query arguments.
|
||||
const queryStringIndex = url.indexOf('?');
|
||||
|
||||
if (queryStringIndex !== -1) {
|
||||
// Merge into existing query arguments.
|
||||
args = Object.assign(getQueryArgs(url), args); // Change working base URL to omit previous query arguments.
|
||||
args = Object.assign(getQueryArgs(url), args);
|
||||
|
||||
// Change working base URL to omit previous query arguments.
|
||||
baseUrl = baseUrl.substr(0, queryStringIndex);
|
||||
}
|
||||
|
||||
return baseUrl + '?' + buildQueryString(args);
|
||||
}
|
||||
|
||||
@@ -1051,6 +1090,7 @@ function addQueryArgs(url = '', args) {
|
||||
* Internal dependencies
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {{[key: string]: QueryArgParsed}} QueryArgObject
|
||||
*/
|
||||
@@ -1072,7 +1112,6 @@ function addQueryArgs(url = '', args) {
|
||||
*
|
||||
* @return {QueryArgParsed|void} Query arg value.
|
||||
*/
|
||||
|
||||
function getQueryArg(url, arg) {
|
||||
return getQueryArgs(url)[arg];
|
||||
}
|
||||
@@ -1082,6 +1121,7 @@ function getQueryArg(url, arg) {
|
||||
* Internal dependencies
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Determines whether the URL contains a given query arg.
|
||||
*
|
||||
@@ -1095,7 +1135,6 @@ function getQueryArg(url, arg) {
|
||||
*
|
||||
* @return {boolean} Whether or not the URL contains the query arg.
|
||||
*/
|
||||
|
||||
function hasQueryArg(url, arg) {
|
||||
return getQueryArg(url, arg) !== undefined;
|
||||
}
|
||||
@@ -1106,6 +1145,7 @@ function hasQueryArg(url, arg) {
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Removes arguments from the query string of the url
|
||||
*
|
||||
@@ -1119,14 +1159,11 @@ function hasQueryArg(url, arg) {
|
||||
*
|
||||
* @return {string} Updated URL.
|
||||
*/
|
||||
|
||||
function removeQueryArgs(url, ...args) {
|
||||
const queryStringIndex = url.indexOf('?');
|
||||
|
||||
if (queryStringIndex === -1) {
|
||||
return url;
|
||||
}
|
||||
|
||||
const query = getQueryArgs(url);
|
||||
const baseURL = url.substr(0, queryStringIndex);
|
||||
args.forEach(arg => delete query[arg]);
|
||||
@@ -1140,6 +1177,7 @@ function removeQueryArgs(url, ...args) {
|
||||
*/
|
||||
|
||||
const USABLE_HREF_REGEXP = /^(?:[a-z]+:|#|\?|\.|\/)/i;
|
||||
|
||||
/**
|
||||
* Prepends "http://" to a url, if it looks like something that is meant to be a TLD.
|
||||
*
|
||||
@@ -1152,18 +1190,14 @@ const USABLE_HREF_REGEXP = /^(?:[a-z]+:|#|\?|\.|\/)/i;
|
||||
*
|
||||
* @return {string} The updated URL.
|
||||
*/
|
||||
|
||||
function prependHTTP(url) {
|
||||
if (!url) {
|
||||
return url;
|
||||
}
|
||||
|
||||
url = url.trim();
|
||||
|
||||
if (!USABLE_HREF_REGEXP.test(url) && !isEmail(url)) {
|
||||
return 'http://' + url;
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
@@ -1206,28 +1240,26 @@ function safeDecodeURI(uri) {
|
||||
*/
|
||||
function filterURLForDisplay(url, maxLength = null) {
|
||||
// Remove protocol and www prefixes.
|
||||
let filteredURL = url.replace(/^(?:https?:)\/\/(?:www\.)?/, ''); // Ends with / and only has that single slash, strip it.
|
||||
let filteredURL = url.replace(/^(?:https?:)\/\/(?:www\.)?/, '');
|
||||
|
||||
// Ends with / and only has that single slash, strip it.
|
||||
if (filteredURL.match(/^[^\/]+\/$/)) {
|
||||
filteredURL = filteredURL.replace('/', '');
|
||||
}
|
||||
|
||||
const mediaRegexp = /([\w|:])*\.(?:jpg|jpeg|gif|png|svg)/;
|
||||
|
||||
if (!maxLength || filteredURL.length <= maxLength || !filteredURL.match(mediaRegexp)) {
|
||||
return filteredURL;
|
||||
} // If the file is not greater than max length, return last portion of URL.
|
||||
|
||||
}
|
||||
|
||||
// If the file is not greater than max length, return last portion of URL.
|
||||
filteredURL = filteredURL.split('?')[0];
|
||||
const urlPieces = filteredURL.split('/');
|
||||
const file = urlPieces[urlPieces.length - 1];
|
||||
|
||||
if (file.length <= maxLength) {
|
||||
return '…' + filteredURL.slice(-maxLength);
|
||||
} // If the file is greater than max length, truncate the file.
|
||||
|
||||
}
|
||||
|
||||
// If the file is greater than max length, truncate the file.
|
||||
const index = file.lastIndexOf('.');
|
||||
const [fileName, extension] = [file.slice(0, index), file.slice(index + 1)];
|
||||
const truncatedFile = fileName.slice(-3) + '.' + extension;
|
||||
@@ -1242,6 +1274,7 @@ var remove_accents_default = /*#__PURE__*/__webpack_require__.n(remove_accents);
|
||||
* External dependencies
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Performs some basic cleanup of a string for use as a post slug.
|
||||
*
|
||||
@@ -1258,17 +1291,20 @@ var remove_accents_default = /*#__PURE__*/__webpack_require__.n(remove_accents);
|
||||
*
|
||||
* @return {string} Processed string.
|
||||
*/
|
||||
|
||||
function cleanForSlug(string) {
|
||||
if (!string) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return remove_accents_default()(string) // Convert each group of whitespace, periods, and forward slashes to a hyphen.
|
||||
.replace(/[\s\./]+/g, '-') // Remove anything that's not a letter, number, underscore or hyphen.
|
||||
.replace(/[^\p{L}\p{N}_-]+/gu, '') // Convert to lowercase
|
||||
.toLowerCase() // Replace multiple hyphens with a single one.
|
||||
.replace(/-+/g, '-') // Remove any remaining leading or trailing hyphens.
|
||||
return remove_accents_default()(string)
|
||||
// Convert each group of whitespace, periods, and forward slashes to a hyphen.
|
||||
.replace(/[\s\./]+/g, '-')
|
||||
// Remove anything that's not a letter, number, underscore or hyphen.
|
||||
.replace(/[^\p{L}\p{N}_-]+/gu, '')
|
||||
// Convert to lowercase
|
||||
.toLowerCase()
|
||||
// Replace multiple hyphens with a single one.
|
||||
.replace(/-+/g, '-')
|
||||
// Remove any remaining leading or trailing hyphens.
|
||||
.replace(/(^-+)|(-+$)/g, '');
|
||||
}
|
||||
|
||||
@@ -1288,11 +1324,9 @@ function cleanForSlug(string) {
|
||||
*/
|
||||
function getFilename(url) {
|
||||
let filename;
|
||||
|
||||
try {
|
||||
filename = new URL(url, 'http://example.com').pathname.split('/').pop();
|
||||
} catch (error) {}
|
||||
|
||||
if (filename) {
|
||||
return filename;
|
||||
}
|
||||
@@ -1312,19 +1346,25 @@ function normalizePath(path) {
|
||||
const splitted = path.split('?');
|
||||
const query = splitted[1];
|
||||
const base = splitted[0];
|
||||
|
||||
if (!query) {
|
||||
return base;
|
||||
} // 'b=1%2C2&c=2&a=5'
|
||||
}
|
||||
|
||||
|
||||
return base + '?' + query // [ 'b=1%2C2', 'c=2', 'a=5' ]
|
||||
.split('&') // [ [ 'b, '1%2C2' ], [ 'c', '2' ], [ 'a', '5' ] ]
|
||||
.map(entry => entry.split('=')) // [ [ 'b', '1,2' ], [ 'c', '2' ], [ 'a', '5' ] ]
|
||||
.map(pair => pair.map(decodeURIComponent)) // [ [ 'a', '5' ], [ 'b, '1,2' ], [ 'c', '2' ] ]
|
||||
.sort((a, b) => a[0].localeCompare(b[0])) // [ [ 'a', '5' ], [ 'b, '1%2C2' ], [ 'c', '2' ] ]
|
||||
.map(pair => pair.map(encodeURIComponent)) // [ 'a=5', 'b=1%2C2', 'c=2' ]
|
||||
.map(pair => pair.join('=')) // 'a=5&b=1%2C2&c=2'
|
||||
// 'b=1%2C2&c=2&a=5'
|
||||
return base + '?' + query
|
||||
// [ 'b=1%2C2', 'c=2', 'a=5' ]
|
||||
.split('&')
|
||||
// [ [ 'b, '1%2C2' ], [ 'c', '2' ], [ 'a', '5' ] ]
|
||||
.map(entry => entry.split('='))
|
||||
// [ [ 'b', '1,2' ], [ 'c', '2' ], [ 'a', '5' ] ]
|
||||
.map(pair => pair.map(decodeURIComponent))
|
||||
// [ [ 'a', '5' ], [ 'b, '1,2' ], [ 'c', '2' ] ]
|
||||
.sort((a, b) => a[0].localeCompare(b[0]))
|
||||
// [ [ 'a', '5' ], [ 'b, '1%2C2' ], [ 'c', '2' ] ]
|
||||
.map(pair => pair.map(encodeURIComponent))
|
||||
// [ 'a=5', 'b=1%2C2', 'c=2' ]
|
||||
.map(pair => pair.join('='))
|
||||
// 'a=5&b=1%2C2&c=2'
|
||||
.join('&');
|
||||
}
|
||||
|
||||
@@ -1333,6 +1373,7 @@ function normalizePath(path) {
|
||||
* Internal dependencies
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Prepends "https://" to a url, if it looks like something that is meant to be a TLD.
|
||||
*
|
||||
@@ -1347,17 +1388,15 @@ function normalizePath(path) {
|
||||
*
|
||||
* @return {string} The updated URL.
|
||||
*/
|
||||
|
||||
function prependHTTPS(url) {
|
||||
if (!url) {
|
||||
return url;
|
||||
} // If url starts with http://, return it as is.
|
||||
|
||||
}
|
||||
|
||||
// If url starts with http://, return it as is.
|
||||
if (url.startsWith('http://')) {
|
||||
return url;
|
||||
}
|
||||
|
||||
url = prependHTTP(url);
|
||||
return url.replace(/^http:/, 'https:');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user