Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function observeRestRequest( req ) {
if ( req.url().match( 'wp-json' ) ) {
// eslint-disable-next-line no-console
console.log( '>>>', req.method(), req.url(), req.postData() );
}
if ( req.url().match( 'google-site-kit/v1/data/' ) ) {
const rawBatchRequest = getQueryArg( req.url(), 'request' );
try {
const batchRequests = JSON.parse( rawBatchRequest );
if ( Array.isArray( batchRequests ) ) {
batchRequests.forEach( ( r ) => {
// eslint-disable-next-line no-console
console.log( '>>>', r.key, r.data );
} );
}
} catch {}
}
}
export async function trashExistingPosts( postType = 'post' ) {
await switchUserToAdmin();
// Visit `/wp-admin/edit.php` so we can see a list of posts and delete them.
const query = addQueryArgs( '', {
post_type: postType,
} ).slice( 1 );
await visitAdminPage( 'edit.php', query );
// If this selector doesn't exist there are no posts for us to delete.
const bulkSelector = await page.$( '#bulk-action-selector-top' );
if ( ! bulkSelector ) {
return;
}
// Select all posts.
await page.waitForSelector( '[id^=cb-select-all-]' );
await page.click( '[id^=cb-select-all-]' );
// Select the "bulk actions" > "trash" option.
await page.select( '#bulk-action-selector-bottom', 'trash' );
// Submit the form to send all draft/scheduled/published posts to the trash.
componentDidMount() {
const { attributes, setAttributes } = this.props;
// This will warn when we have `id` defined, while `url` is undefined.
// This may help track this issue: https://github.com/wordpress-mobile/WordPress-Android/issues/9768
// where a cancelled image upload was resulting in a subsequent crash.
if ( attributes.id && ! attributes.url ) {
// eslint-disable-next-line no-console
console.warn( 'Attributes has id with no url.' );
}
if ( attributes.id && attributes.url && ! isURL( attributes.url ) ) {
if ( attributes.url.indexOf( 'file:' ) === 0 ) {
requestMediaImport( attributes.url, ( mediaId, mediaUri ) => {
if ( mediaUri ) {
setAttributes( { url: mediaUri, id: mediaId } );
}
} );
}
mediaUploadSync();
}
}
export default ( { blockName, postId, stripeConnectUrl } ) => {
if ( ! isURL( stripeConnectUrl ) ) {
return null;
}
let url = stripeConnectUrl;
if ( postId ) {
try {
const state = getQueryArg( stripeConnectUrl, 'state' );
const decodedState = JSON.parse( atob( state ) );
decodedState.from_editor_post_id = postId;
url = addQueryArgs( stripeConnectUrl, { state: btoa( JSON.stringify( decodedState ) ) } );
} catch ( err ) {
if ( process.env.NODE_ENV !== 'production' ) {
console.error( err ); // eslint-disable-line no-console
}
}
}
return (
if ( ! isValidProtocol( protocol ) ) {
return false;
}
// Add some extra checks for http(s) URIs, since these are the most common use-case.
// This ensures URIs with an http protocol have exactly two forward slashes following the protocol.
if ( startsWith( protocol, 'http' ) && ! /^https?:\/\/[^\/\s]/i.test( trimmedHref ) ) {
return false;
}
const authority = getAuthority( trimmedHref );
if ( ! isValidAuthority( authority ) ) {
return false;
}
const path = getPath( trimmedHref );
if ( path && ! isValidPath( path ) ) {
return false;
}
const queryString = getQueryString( trimmedHref );
if ( queryString && ! isValidQueryString( queryString ) ) {
return false;
}
const fragment = getFragment( trimmedHref );
if ( fragment && ! isValidFragment( fragment ) ) {
return false;
}
}
// Validate anchor links.
export function isValidHref( href ) {
if ( ! href ) {
return false;
}
const trimmedHref = href.trim();
if ( ! trimmedHref ) {
return false;
}
// Does the href start with something that looks like a URL protocol?
if ( /^\S+:/.test( trimmedHref ) ) {
const protocol = getProtocol( trimmedHref );
if ( ! isValidProtocol( protocol ) ) {
return false;
}
// Add some extra checks for http(s) URIs, since these are the most common use-case.
// This ensures URIs with an http protocol have exactly two forward slashes following the protocol.
if ( startsWith( protocol, 'http' ) && ! /^https?:\/\/[^\/\s]/i.test( trimmedHref ) ) {
return false;
}
const authority = getAuthority( trimmedHref );
if ( ! isValidAuthority( authority ) ) {
return false;
}
const path = getPath( trimmedHref );
}
// Does the href start with something that looks like a URL protocol?
if ( /^\S+:/.test( trimmedHref ) ) {
const protocol = getProtocol( trimmedHref );
if ( ! isValidProtocol( protocol ) ) {
return false;
}
// Add some extra checks for http(s) URIs, since these are the most common use-case.
// This ensures URIs with an http protocol have exactly two forward slashes following the protocol.
if ( startsWith( protocol, 'http' ) && ! /^https?:\/\/[^\/\s]/i.test( trimmedHref ) ) {
return false;
}
const authority = getAuthority( trimmedHref );
if ( ! isValidAuthority( authority ) ) {
return false;
}
const path = getPath( trimmedHref );
if ( path && ! isValidPath( path ) ) {
return false;
}
const queryString = getQueryString( trimmedHref );
if ( queryString && ! isValidQueryString( queryString ) ) {
return false;
}
const fragment = getFragment( trimmedHref );
if ( fragment && ! isValidFragment( fragment ) ) {
// This ensures URIs with an http protocol have exactly two forward slashes following the protocol.
if ( startsWith( protocol, 'http' ) && ! /^https?:\/\/[^\/\s]/i.test( trimmedHref ) ) {
return false;
}
const authority = getAuthority( trimmedHref );
if ( ! isValidAuthority( authority ) ) {
return false;
}
const path = getPath( trimmedHref );
if ( path && ! isValidPath( path ) ) {
return false;
}
const queryString = getQueryString( trimmedHref );
if ( queryString && ! isValidQueryString( queryString ) ) {
return false;
}
const fragment = getFragment( trimmedHref );
if ( fragment && ! isValidFragment( fragment ) ) {
return false;
}
}
// Validate anchor links.
if ( startsWith( trimmedHref, '#' ) && ! isValidFragment( trimmedHref ) ) {
return false;
}
return true;
// Does the href start with something that looks like a URL protocol?
if ( /^\S+:/.test( trimmedHref ) ) {
const protocol = getProtocol( trimmedHref );
if ( ! isValidProtocol( protocol ) ) {
return false;
}
// Add some extra checks for http(s) URIs, since these are the most common use-case.
// This ensures URIs with an http protocol have exactly two forward slashes following the protocol.
if ( startsWith( protocol, 'http' ) && ! /^https?:\/\/[^\/\s]/i.test( trimmedHref ) ) {
return false;
}
const authority = getAuthority( trimmedHref );
if ( ! isValidAuthority( authority ) ) {
return false;
}
const path = getPath( trimmedHref );
if ( path && ! isValidPath( path ) ) {
return false;
}
const queryString = getQueryString( trimmedHref );
if ( queryString && ! isValidQueryString( queryString ) ) {
return false;
}
const fragment = getFragment( trimmedHref );
if ( fragment && ! isValidFragment( fragment ) ) {
return false;
return false;
}
// Add some extra checks for http(s) URIs, since these are the most common use-case.
// This ensures URIs with an http protocol have exactly two forward slashes following the protocol.
if ( startsWith( protocol, 'http' ) && ! /^https?:\/\/[^\/\s]/i.test( trimmedHref ) ) {
return false;
}
const authority = getAuthority( trimmedHref );
if ( ! isValidAuthority( authority ) ) {
return false;
}
const path = getPath( trimmedHref );
if ( path && ! isValidPath( path ) ) {
return false;
}
const queryString = getQueryString( trimmedHref );
if ( queryString && ! isValidQueryString( queryString ) ) {
return false;
}
const fragment = getFragment( trimmedHref );
if ( fragment && ! isValidFragment( fragment ) ) {
return false;
}
}
// Validate anchor links.
if ( startsWith( trimmedHref, '#' ) && ! isValidFragment( trimmedHref ) ) {