From c685ff323dd110bc49b02e4790969c09b31aeb27 Mon Sep 17 00:00:00 2001 From: Sara Marcondes Date: Tue, 30 Jun 2020 07:25:44 -0700 Subject: [PATCH] Misc.: Remove problematic "blacklist"/"whitelist" language #43395 (#43690) * Misc.: Remove problematic "blacklist"/"whitelist" language #43395 * Tours: Rename selector for clarity --- bin/validate-config-keys.js | 2 +- .../advanced/accepted-filenames.jsx | 8 +++- .../acquire-intent/site-title.tsx | 1 + client/lib/i18n-utils/empathy-mode.js | 4 +- client/server/pages/index.js | 6 +-- client/server/sanitize/index.js | 8 ++-- .../happychat/test/middleware-calypso.js | 4 +- client/state/logstash/actions.ts | 2 +- client/state/nps-survey/selectors.js | 4 +- client/state/plugins/premium/selectors.js | 43 +++++++++++-------- .../state/plugins/premium/test/selectors.js | 4 +- .../posts/actions/start-editing-post-copy.js | 6 +-- .../state/ui/guided-tours/selectors/index.js | 7 +-- packages/i18n-calypso-cli/test/i18n.js | 2 +- 14 files changed, 59 insertions(+), 42 deletions(-) diff --git a/bin/validate-config-keys.js b/bin/validate-config-keys.js index b607e46c2c82f..53531c279e25e 100644 --- a/bin/validate-config-keys.js +++ b/bin/validate-config-keys.js @@ -33,7 +33,7 @@ const environmentKeys = fs .readdirSync( configRoot, { encoding: 'utf8' } ) .filter( ( filename ) => /\.json$/.test( path.basename( filename ) ) ) // only the JSON config files .filter( ( filename ) => '_shared.json' !== filename ) // base config for all environments - .filter( ( filename ) => 'client.json' !== filename ) // whitelist of keys allowed in client + .filter( ( filename ) => 'client.json' !== filename ) // list of keys allowed in client .filter( ( filename ) => ! /secrets/g.test( filename ) ) // secret tokens not part of this system .map( ( filename ) => [ filename, Object.keys( parseConfig( filename ) ) ] ); diff --git a/client/extensions/wp-super-cache/components/advanced/accepted-filenames.jsx b/client/extensions/wp-super-cache/components/advanced/accepted-filenames.jsx index 9d728872bbb61..2ab404547e1be 100644 --- a/client/extensions/wp-super-cache/components/advanced/accepted-filenames.jsx +++ b/client/extensions/wp-super-cache/components/advanced/accepted-filenames.jsx @@ -94,7 +94,7 @@ class AcceptedFilenames extends Component {
{ translate( 'Do not cache these page types.' ) } - + { /* eslint-disable-next-line wpcalypso/jsx-classname-namespace */ } { translate( ' See the {{a}}Conditional Tags{{/a}} ' + @@ -117,10 +117,14 @@ class AcceptedFilenames extends Component { { this.renderToggle( 'single', translate( 'Single Posts (is_single)' ) ) } { this.renderToggle( 'pages', translate( 'Pages (is_page)' ) ) } { this.renderToggle( 'frontpage', translate( 'Front Page (is_front_page)' ) ) } + + { /* eslint-disable-next-line wpcalypso/jsx-classname-namespace */ }
{ this.renderToggle( 'home', translate( 'Home (is_home)' ), 'frontpage' ) }
{ this.renderToggle( 'archives', translate( 'Archives (is_archive)' ) ) } + + { /* eslint-disable-next-line wpcalypso/jsx-classname-namespace */ }
{ this.renderToggle( 'tag', translate( 'Tags (is_tag)' ), 'archives' ) } { this.renderToggle( @@ -154,7 +158,7 @@ class AcceptedFilenames extends Component { - { translate( 'Whitelisted filenames:' ) } + { translate( 'Allowed filenames:' ) } = ( { onSubmit } ) => { autoComplete="off" placeholder={ placeHolder } autoCorrect="off" + // Unable to remove this instance due to it being a HotJar term: https://github.com/Automattic/wp-calypso/pull/43348#discussion_r442015229 data-hj-whitelist >

diff --git a/client/lib/i18n-utils/empathy-mode.js b/client/lib/i18n-utils/empathy-mode.js index 5d5fd65b9d625..1f8e4fb535f18 100644 --- a/client/lib/i18n-utils/empathy-mode.js +++ b/client/lib/i18n-utils/empathy-mode.js @@ -41,7 +41,7 @@ export function initLanguageEmpathyMode() { const i18nEmpathy = new I18N(); const i18nEmpathyTranslate = i18nEmpathy.translate.bind( i18nEmpathy ); const i18nEmpathyRegisterHook = i18nEmpathy.registerTranslateHook.bind( i18nEmpathy ); - const translationsWhitelist = [ defaultUntranslatedPlacehoder ]; + const availableEmpathyTranslations = [ defaultUntranslatedPlacehoder ]; i18n.translateHooks.forEach( i18nEmpathyRegisterHook ); @@ -51,7 +51,7 @@ export function initLanguageEmpathyMode() { if ( ! isActive || locale === i18n.defaultLocaleSlug || - translationsWhitelist.includes( options.original ) + availableEmpathyTranslations.includes( options.original ) ) { return translation; } diff --git a/client/server/pages/index.js b/client/server/pages/index.js index 0da7b0516065e..640d8fcf4222a 100644 --- a/client/server/pages/index.js +++ b/client/server/pages/index.js @@ -263,10 +263,10 @@ function getDefaultContext( request, entrypoint = 'entry-main' ) { let initialServerState = {}; let lang = config( 'i18n_default_locale_slug' ); const bodyClasses = []; - // We don't compare context.query against a whitelist here. Whitelists are route-specific, + // We don't compare context.query against an allowed list here. Explicit allowance lists are route-specific, // i.e. they can be created by route-specific middleware. `getDefaultContext` is always // called before route-specific middleware, so it's up to the cache *writes* in server - // render to make sure that Redux state and markup are only cached for whitelisted query args. + // render to make sure that Redux state and markup are only cached for specified query args. const cacheKey = getNormalizedPath( request.path, request.query ); const geoLocation = ( request.headers[ 'x-geoip-country-code' ] || '' ).toLowerCase(); const devEnvironments = [ 'development', 'jetpack-cloud-development' ]; @@ -976,7 +976,7 @@ export default function pages() { } ); } ); - // catchall to render 404 for all routes not whitelisted in client/sections + // catchall to render 404 for all routes not explicitly allowed in client/sections app.use( render404() ); // Error handling middleware for displaying the server error 500 page must be the very last middleware defined diff --git a/client/server/sanitize/index.js b/client/server/sanitize/index.js index 016804473f720..455ca44727975 100644 --- a/client/server/sanitize/index.js +++ b/client/server/sanitize/index.js @@ -1,3 +1,5 @@ +/* eslint-disable jsdoc/check-values */ + /** * Encode single characters with backslashes. * @@ -41,15 +43,15 @@ function jsSlashEncoder( charStr ) { /** * Create JSON serialized string suitable for inclusion in HTML * - * @param {mixed} value The variable to be serialized + * @param {any} value The variable to be serialized * @returns {string} JSON serialized string **/ exports.jsonStringifyForHtml = function ( value ) { - const jsonInHtmlBlacklist = /[^\x22,\-\.0-9:A-Z\[\x5C\]_a-z{}]/g; + const jsonInHtmlFilter = /[^\x22,\-.0-9:A-Z[\x5C]_a-z{}]/g; const cdataClose = /\]\](?:>|\\x3E|\\u003E)/gi; return ( JSON.stringify( value ) - .replace( jsonInHtmlBlacklist, jsSlashEncoder ) + .replace( jsonInHtmlFilter, jsSlashEncoder ) // prevent breaking out of CDATA context. Escaping < below is sufficient // to prevent opening a CDATA context. .replace( cdataClose, '\\x5D\\x5D\\x3E' ) diff --git a/client/state/happychat/test/middleware-calypso.js b/client/state/happychat/test/middleware-calypso.js index 46466eadea02c..be922deab3239 100644 --- a/client/state/happychat/test/middleware-calypso.js +++ b/client/state/happychat/test/middleware-calypso.js @@ -214,7 +214,7 @@ describe( 'middleware', () => { expect( store.dispatch.mock.calls[ 1 ][ 0 ].payload.text ).toBe( 'def' ); } ); - test( 'should only send a timeline event for whitelisted tracks events', () => { + test( 'should only send a timeline event for allowed tracks events', () => { const analyticsMeta = [ { type: ANALYTICS_EVENT_RECORD, @@ -326,7 +326,7 @@ describe( 'middleware', () => { sendActionLogsAndEvents( store, action ); // All 4 analytics records will be sent to the "firehose" log - // The two whitelisted analytics events and the SITE_SETTINGS_SAVE_SUCCESS itself + // The two allowed analytics events and the SITE_SETTINGS_SAVE_SUCCESS itself // will be sent as customer events expect( store.dispatch ).toHaveBeenCalledTimes( 7 ); expect( store.dispatch.mock.calls[ 0 ][ 0 ].type ).toBe( HAPPYCHAT_IO_SEND_MESSAGE_EVENT ); diff --git a/client/state/logstash/actions.ts b/client/state/logstash/actions.ts index 5deac897dec48..8ef3879c94c70 100644 --- a/client/state/logstash/actions.ts +++ b/client/state/logstash/actions.ts @@ -13,7 +13,7 @@ interface LogToLogstashParams { /** * Feature name. * - * Should be whitelisted. @see D31385-code + * Should be explicitly allowed. @see D31385-code */ feature: 'calypso_ssr' | 'calypso_client'; message: string; diff --git a/client/state/nps-survey/selectors.js b/client/state/nps-survey/selectors.js index 2adff634664bb..c2331407c8486 100644 --- a/client/state/nps-survey/selectors.js +++ b/client/state/nps-survey/selectors.js @@ -10,7 +10,7 @@ import { get } from 'lodash'; import { NOT_SUBMITTED, SUBMITTING, SUBMIT_FAILURE, SUBMITTED } from './constants'; import { getSectionName } from 'state/ui/selectors'; -const SECTION_NAME_WHITELIST = [ +const ALLOWED_SECTION_NAMES = [ 'discover', 'menus', 'people', @@ -33,7 +33,7 @@ export function isSessionEligibleForNpsSurvey( state ) { export function isSectionEligibleForNpsSurvey( state ) { const sectionName = getSectionName( state ); - return SECTION_NAME_WHITELIST.indexOf( sectionName ) > -1; + return ALLOWED_SECTION_NAMES.indexOf( sectionName ) > -1; } export function isSectionAndSessionEligibleForNpsSurvey( state ) { diff --git a/client/state/plugins/premium/selectors.js b/client/state/plugins/premium/selectors.js index 835a036fabd90..6c9edc796d519 100644 --- a/client/state/plugins/premium/selectors.js +++ b/client/state/plugins/premium/selectors.js @@ -24,35 +24,44 @@ export const hasRequested = function ( state, siteId ) { return state.plugins.premium.hasRequested[ siteId ]; }; -export const getPluginsForSite = function ( state, siteId, whitelist = false ) { +/** + * Gets the list of plugins for a site and optionally filters to a single specific + * plugin. + * + * @param {object} state The current state. + * @param {number} siteId The site ID. + * @param {string?} forPlugin Name of a specific plugin to filter for, `false` otherwise to return the full list. + * @returns {Array} The list of plugins. + */ +export const getPluginsForSite = function ( state, siteId, forPlugin = false ) { const pluginList = state.plugins.premium.plugins[ siteId ]; if ( typeof pluginList === 'undefined' ) { return []; } // patch to solve a bug in jp 4.3 ( https://github.com/Automattic/jetpack/issues/5498 ) - if ( whitelist === 'backups' || whitelist === 'scan' ) { - whitelist = 'vaultpress'; + if ( forPlugin === 'backups' || forPlugin === 'scan' ) { + forPlugin = 'vaultpress'; } return filter( pluginList, ( plugin ) => { // eslint-disable-next-line no-extra-boolean-cast - if ( !! whitelist ) { - return whitelist === plugin.slug; + if ( !! forPlugin ) { + return forPlugin === plugin.slug; } return true; } ); }; -export const isStarted = function ( state, siteId, whitelist = false ) { - const pluginList = getPluginsForSite( state, siteId, whitelist ); +export const isStarted = function ( state, siteId, forPlugin = false ) { + const pluginList = getPluginsForSite( state, siteId, forPlugin ); return ! every( pluginList, ( item ) => { return 'wait' === item.status; } ); }; -export const isFinished = function ( state, siteId, whitelist = false ) { - const pluginList = getPluginsForSite( state, siteId, whitelist ); +export const isFinished = function ( state, siteId, forPlugin = false ) { + const pluginList = getPluginsForSite( state, siteId, forPlugin ); if ( pluginList.length === 0 ) { return true; } @@ -62,8 +71,8 @@ export const isFinished = function ( state, siteId, whitelist = false ) { } ); }; -export const isInstalling = function ( state, siteId, whitelist = false ) { - const pluginList = getPluginsForSite( state, siteId, whitelist ); +export const isInstalling = function ( state, siteId, forPlugin = false ) { + const pluginList = getPluginsForSite( state, siteId, forPlugin ); if ( pluginList.length === 0 ) { return false; } @@ -74,8 +83,8 @@ export const isInstalling = function ( state, siteId, whitelist = false ) { } ); }; -export const getActivePlugin = function ( state, siteId, whitelist = false ) { - const pluginList = getPluginsForSite( state, siteId, whitelist ); +export const getActivePlugin = function ( state, siteId, forPlugin = false ) { + const pluginList = getPluginsForSite( state, siteId, forPlugin ); const plugin = find( pluginList, ( item ) => { return ! includes( [ 'done', 'wait' ], item.status ) && item.error === null; } ); @@ -85,8 +94,8 @@ export const getActivePlugin = function ( state, siteId, whitelist = false ) { return plugin; }; -export const getNextPlugin = function ( state, siteId, whitelist = false ) { - const pluginList = getPluginsForSite( state, siteId, whitelist ); +export const getNextPlugin = function ( state, siteId, forPlugin = false ) { + const pluginList = getPluginsForSite( state, siteId, forPlugin ); const plugin = find( pluginList, ( item ) => { return 'wait' === item.status && item.error === null; } ); @@ -97,8 +106,8 @@ export const getNextPlugin = function ( state, siteId, whitelist = false ) { }; export const getPluginKeys = createSelector( - ( state, siteId, whitelist = false ) => { - const pluginList = getPluginsForSite( state, siteId, whitelist ); + ( state, siteId, forPlugin = false ) => { + const pluginList = getPluginsForSite( state, siteId, forPlugin ); return pluginList.reduce( ( keys, plugin ) => { const key = get( plugin, 'key' ); diff --git a/client/state/plugins/premium/test/selectors.js b/client/state/plugins/premium/test/selectors.js index f4c053350ba3a..76fd52676b5b0 100644 --- a/client/state/plugins/premium/test/selectors.js +++ b/client/state/plugins/premium/test/selectors.js @@ -91,11 +91,11 @@ describe( 'Premium Plugin Selectors', () => { expect( isInstalling( state, 'installing.site' ) ).toBe( true ); } ); - test( 'Should get `true` if there is a plugin installing on the requested site, using whitelist', () => { + test( 'Should get `true` if there is a plugin installing on the requested site, filtering for a specified plugin (akismet)', () => { expect( isInstalling( state, 'installing.site', 'akismet' ) ).toBe( true ); } ); - test( 'Should get `true` if there is a plugin configuring on the requested site, using whitelist', () => { + test( 'Should get `true` if there is a plugin configuring on the requested site, filtering for a specified plugin (akismet)', () => { expect( isInstalling( state, 'config.site', 'akismet' ) ).toBe( true ); } ); diff --git a/client/state/posts/actions/start-editing-post-copy.js b/client/state/posts/actions/start-editing-post-copy.js index fbc0a394d6671..d82b42ff2a6dd 100644 --- a/client/state/posts/actions/start-editing-post-copy.js +++ b/client/state/posts/actions/start-editing-post-copy.js @@ -35,14 +35,14 @@ export const startEditingPostCopy = ( siteId, postToCopyId ) => ( dispatch ) => postAttributes.featured_image = getFeaturedImageId( postToCopy ); /** - * A post metadata whitelist for the `updatePostMetadata()` action. + * A list of allowed post metadata for the `updatePostMetadata()` action. * * This is needed because blindly passing all post metadata to `editPost()` * causes unforeseeable issues, such as Publicize not triggering on the copied post. * * @see https://github.com/Automattic/wp-calypso/issues/14840 */ - const metadataWhitelist = [ 'geo_latitude', 'geo_longitude', 'geo_address', 'geo_public' ]; + const allowedMetadata = [ 'geo_latitude', 'geo_longitude', 'geo_address', 'geo_public' ]; // Filter the post metadata to include only the ones we want to copy, // use only the `key` and `value` properties (and, most importantly exclude `id`), @@ -50,7 +50,7 @@ export const startEditingPostCopy = ( siteId, postToCopyId ) => ( dispatch ) => const copiedMetadata = reduce( postToCopy.metadata, ( copiedMeta, { key, value } ) => { - if ( includes( metadataWhitelist, key ) ) { + if ( includes( allowedMetadata, key ) ) { copiedMeta.push( { key, value, operation: 'update' } ); } return copiedMeta; diff --git a/client/state/ui/guided-tours/selectors/index.js b/client/state/ui/guided-tours/selectors/index.js index 08ebf655653e2..d2c8cc6206cda 100644 --- a/client/state/ui/guided-tours/selectors/index.js +++ b/client/state/ui/guided-tours/selectors/index.js @@ -31,7 +31,7 @@ import createSelector from 'lib/create-selector'; import findOngoingTour from './find-ongoing-tour'; import getToursHistory from './get-tours-history'; -const BLACKLISTED_SECTIONS = [ +const SECTIONS_WITHOUT_TOURS = [ 'signup', 'upgrades', // checkout 'checkout-thank-you', // thank you page @@ -149,7 +149,8 @@ const findTriggeredTour = ( state ) => { } ); }; -const isSectionBlacklisted = ( state ) => includes( BLACKLISTED_SECTIONS, getSectionName( state ) ); +const doesSectionAllowTours = ( state ) => + ! includes( SECTIONS_WITHOUT_TOURS, getSectionName( state ) ); export const hasTourJustBeenVisible = createSelector( ( state, now = Date.now() ) => { @@ -163,7 +164,7 @@ export const hasTourJustBeenVisible = createSelector( [ getActionLog ] ); -const shouldBailAllTours = ( state ) => isSectionBlacklisted( state ); +const shouldBailAllTours = ( state ) => ! doesSectionAllowTours( state ); const shouldBailNewTours = ( state ) => hasTourJustBeenVisible( state ); diff --git a/packages/i18n-calypso-cli/test/i18n.js b/packages/i18n-calypso-cli/test/i18n.js index 58ae30ecedd14..596388a5e0227 100644 --- a/packages/i18n-calypso-cli/test/i18n.js +++ b/packages/i18n-calypso-cli/test/i18n.js @@ -8,7 +8,7 @@ const path = require( 'path' ); */ const i18n = require( '..' ); -// generate whitelist file +// generate allowed file const sourceFiles = [ 'examples/i18n-test-examples.jsx', 'examples/i18n-test-example-second-file.jsx',