Skip to content

Commit

Permalink
♻️ Start moving URL helpers into core (#34399)
Browse files Browse the repository at this point in the history
* Move query string parsing into core

* Update dep-check config

* Move query string parsing helper tests

* Fix typo

* Restore deleted forbidden-terms rule

* Update single imports of helpers

* Update multi-imports of url helpers

* Fix straggler imports

* Lint fixes
  • Loading branch information
rcebulko authored May 17, 2021
1 parent 809e46f commit 7478045
Show file tree
Hide file tree
Showing 55 changed files with 173 additions and 222 deletions.
2 changes: 1 addition & 1 deletion 3p/viqeoplayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
import {getData} from '../src/event-helper';
import {loadScript} from './3p';
import {tryDecodeUriComponent} from '../src/url';
import {tryDecodeUriComponent} from '../src/core/types/string/url';

/**
* @param {Window} global
Expand Down
2 changes: 1 addition & 1 deletion ads/alp/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ import {
addParamToUrl,
isLocalhostOrigin,
isProxyOrigin,
parseQueryString,
parseUrlDeprecated,
} from '../../src/url';
import {closest, openWindowDialog} from '../../src/dom';
import {dev} from '../../src/log';
import {dict} from '../../src/core/types/object';
import {parseQueryString} from '../../src/core/types/string/url';
import {urls} from '../../src/config';

/**
Expand Down
2 changes: 1 addition & 1 deletion ads/google/a4a/traffic-experiments.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
mergeExperimentIds,
} from './utils';
import {Services} from '../../../src/services';
import {parseQueryString} from '../../../src/url';
import {parseQueryString} from '../../../src/core/types/string/url';

/** @typedef {{
* control: string,
Expand Down
2 changes: 1 addition & 1 deletion ads/vendors/adventive.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import {addParamsToUrl} from '../../src/url.js';
import {addParamsToUrl} from '../../src/url';
import {dict, hasOwn} from '../../src/core/types/object';
import {endsWith} from '../../src/core/types/string';
import {loadScript, validateData, writeScript} from '../../3p/3p';
Expand Down
2 changes: 1 addition & 1 deletion ads/vendors/firstimpression.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import {parseQueryString} from '../../src/url';
import {parseQueryString} from '../../src/core/types/string/url';
import {validateData, writeScript} from '../../3p/3p';

/**
Expand Down
2 changes: 1 addition & 1 deletion ads/vendors/netletix.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import {addParamsToUrl, assertHttpsUrl} from '../../src/url.js';
import {addParamsToUrl, assertHttpsUrl} from '../../src/url';
import {dev} from '../../src/log.js';
import {dict} from '../../src/core/types/object';
import {loadScript, validateData, writeScript} from '../../3p/3p';
Expand Down
2 changes: 1 addition & 1 deletion ads/vendors/videonow.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import {loadScript, validateData} from '../../3p/3p';
import {parseJson} from '../../src/core/types/object/json';
import {tryDecodeUriComponent} from '../../src/url';
import {tryDecodeUriComponent} from '../../src/core/types/string/url';

/**
* @param {!Window} global
Expand Down
6 changes: 4 additions & 2 deletions build-system/test-configs/dep-check-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ exports.rules = [
'3p/**->src/core/types/index.js',
'3p/**->src/core/types/object/index.js',
'3p/**->src/core/types/string/index.js',
'3p/**->src/core/types/string/url.js',
'3p/**->src/log.js',
'3p/**->src/style.js',
'3p/**->src/url.js',
Expand Down Expand Up @@ -120,18 +121,19 @@ exports.rules = [
mustNotDependOn: 'src/**/*.js',
allowlist: [
'ads/**->src/utils/dom-fingerprint.js',
'ads/**->src/core/constants/consent-state.js',
'ads/**->src/core/error.js',
'ads/**->src/core/types/array.js',
'ads/**->src/core/types/function/index.js',
'ads/**->src/core/types/index.js',
'ads/**->src/core/types/object/index.js',
'ads/**->src/core/types/string/index.js',
'ads/**->src/core/types/string/url.js',
'ads/**->src/log.js',
'ads/**->src/mode.js',
'ads/**->src/url.js',
'ads/**->src/core/types/array.js',
'ads/**->src/static-template.js',
'ads/**->src/style.js',
'ads/**->src/core/constants/consent-state.js',
'ads/**->src/internal-version.js',
// ads/google/a4a doesn't contain 3P ad code and should probably move
// somewhere else at some point
Expand Down
10 changes: 1 addition & 9 deletions build-system/test-configs/forbidden-terms.js
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ const forbiddenTermsSrcInclusive = {
'validator/js/engine/validator.js',
'validator/js/webui/webui.js',
'src/url.js',
'src/url-try-decode-uri-component.js',
'src/core/types/string/url.js',
'src/core/types/string/bytes.js',
],
},
Expand Down Expand Up @@ -948,14 +948,6 @@ const forbiddenTermsSrcInclusive = {
},
'\\.indexOf\\(.*===?.*\\.length':
'use endsWith helper in src/core/types/string',
'/url-parse-query-string': {
message: 'Import parseQueryString from `src/url.js`',
allowlist: [
'build-system/tasks/check-types.js',
'src/mode.js',
'src/url.js',
],
},
'\\.trim(Left|Right)\\(\\)': {
message: 'Unsupported on IE; use trim() or a helper instead.',
allowlist: ['validator/js/engine/validator.js'],
Expand Down
3 changes: 2 additions & 1 deletion extensions/amp-a4a/0.1/amp-a4a.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
generateSentinel,
getDefaultBootstrapBaseUrl,
} from '../../../src/3p-frame';
import {assertHttpsUrl, tryDecodeUriComponent} from '../../../src/url';
import {assertHttpsUrl} from '../../../src/url';
import {cancellation, isCancellation} from '../../../src/error-reporting';
import {createElementWithAttributes} from '../../../src/dom';
import {createSecureDocSkeleton, createSecureFrame} from './secure-frame';
Expand Down Expand Up @@ -64,6 +64,7 @@ import {
} from '../../../src/utils/intersection';
import {isAdPositionAllowed} from '../../../src/ad-helper';
import {isArray, isEnumValue, isObject} from '../../../src/core/types';
import {tryDecodeUriComponent} from '../../../src/core/types/string/url';

import {listenOnce} from '../../../src/event-helper';
import {
Expand Down
3 changes: 2 additions & 1 deletion extensions/amp-access-scroll/0.1/scroll-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ import {Relay} from './scroll-relay';
import {ScrollBar} from './scroll-bar';
import {Services} from '../../../src/services';
import {Sheet} from './scroll-sheet';
import {addParamToUrl, isProxyOrigin, parseQueryString} from '../../../src/url';
import {addParamToUrl, isProxyOrigin} from '../../../src/url';
import {buildUrl, connectHostname} from './scroll-url';
import {createElementWithAttributes} from '../../../src/dom';
import {dict} from '../../../src/core/types/object';
import {installStylesForDoc} from '../../../src/style-installer';
import {parseQueryString} from '../../../src/core/types/string/url';

const TAG = 'amp-access-scroll-elt';
/**
Expand Down
3 changes: 2 additions & 1 deletion extensions/amp-access/0.1/amp-access-source.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ import {AccessServerJwtAdapter} from './amp-access-server-jwt';
import {AccessVendorAdapter} from './amp-access-vendor';
import {Deferred} from '../../../src/core/data-structures/promise';
import {Services} from '../../../src/services';
import {assertHttpsUrl, parseQueryString} from '../../../src/url';
import {assertHttpsUrl} from '../../../src/url';
import {dev, user, userAssert} from '../../../src/log';
import {dict, getValueForExpr} from '../../../src/core/types/object';
import {getLoginUrl, openLoginDialog} from './login-dialog';
import {isExperimentOn} from '../../../src/experiments';
import {isObject} from '../../../src/core/types';
import {parseQueryString} from '../../../src/core/types/string/url';
import {triggerAnalyticsEvent} from '../../../src/analytics';

/** @const */
Expand Down
6 changes: 3 additions & 3 deletions extensions/amp-access/0.1/amp-login-done-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
* limitations under the License.
*/

import {assertAbsoluteHttpOrHttpsUrl} from '../../../src/url';
import {listen} from '../../../src/event-helper';
import {
assertAbsoluteHttpOrHttpsUrl,
parseQueryString,
tryDecodeUriComponent,
} from '../../../src/url';
import {listen} from '../../../src/event-helper';
} from '../../../src/core/types/string/url';

/**
* @private Visible for testing.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ import {
lineDelimitedStreamer,
metaJsonCreativeGrouper,
} from '../../../ads/google/a4a/line-delimited-response-handler';
import {parseQueryString} from '../../../src/url';
import {parseQueryString} from '../../../src/core/types/string/url';
import {stringHash32} from '../../../src/core/types/string';
import {tryParseJson} from '../../../src/core/types/object/json';

Expand Down
3 changes: 2 additions & 1 deletion extensions/amp-analytics/0.1/linker-reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
import {getService, registerServiceBuilder} from '../../../src/service';
import {hasOwn} from '../../../src/core/types/object';
import {parseLinker} from './linker';
import {parseQueryString, removeParamsFromSearch} from '../../../src/url';
import {parseQueryString} from '../../../src/core/types/string/url';
import {removeParamsFromSearch} from '../../../src/url';

import {user} from '../../../src/log';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import {Services} from '../../../src/services';
import {buildUrl} from '../../../ads/google/a4a/shared/url-builder';
import {dict} from '../../../src/core/types/object';
import {parseQueryString} from '../../../src/url';
import {parseQueryString} from '../../../src/core/types/string/url';

/**
* @implements {./ad-network-config.AdNetworkConfigDef}
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-consent/0.1/linker-reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import {hasOwn} from '../../../src/core/types/object';
import {parseLinker} from './linker';
import {parseQueryString} from '../../../src/url';
import {parseQueryString} from '../../../src/core/types/string/url';
import {user} from '../../../src/log';

const TAG = 'amp-consent/linker-reader';
Expand Down
7 changes: 2 additions & 5 deletions extensions/amp-dailymotion/0.1/amp-dailymotion.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ import {Deferred} from '../../../src/core/data-structures/promise';
import {PauseHelper} from '../../../src/utils/pause-helper';
import {Services} from '../../../src/services';
import {VideoEvents} from '../../../src/video-interface';
import {
addParamToUrl,
addParamsToUrl,
parseQueryString,
} from '../../../src/url';
import {addParamToUrl, addParamsToUrl} from '../../../src/url';
import {
createFrameFor,
mutedOrUnmutedEvent,
Expand All @@ -41,6 +37,7 @@ import {
import {getData, listen} from '../../../src/event-helper';
import {installVideoManagerForDoc} from '../../../src/service/video-manager-impl';
import {isLayoutSizeDefined} from '../../../src/layout';
import {parseQueryString} from '../../../src/core/types/string/url';

const TAG = 'amp-dailymotion';

Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-form/0.1/amp-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import {
SOURCE_ORIGIN_PARAM,
addParamsToUrl,
isProxyOrigin,
parseQueryString,
serializeQueryString,
} from '../../../src/url';
import {Services} from '../../../src/services';
Expand Down Expand Up @@ -65,6 +64,7 @@ import {installFormProxy} from './form-proxy';
import {installStylesForDoc} from '../../../src/style-installer';
import {isAmp4Email} from '../../../src/format';
import {isArray, toArray} from '../../../src/core/types/array';
import {parseQueryString} from '../../../src/core/types/string/url';
import {
setupAMPCors,
setupInit,
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-form/0.1/test/test-amp-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import {
isFormDataWrapper,
} from '../../../../src/form-data-wrapper';
import {fromIterator} from '../../../../src/core/types/array';
import {parseQueryString} from '../../../../src/url.js';
import {parseQueryString} from '../../../../src/core/types/string/url';
import {
setCheckValiditySupportedForTesting,
setReportValiditySupportedForTesting,
Expand Down
3 changes: 2 additions & 1 deletion extensions/amp-skimlinks/0.1/test/test-waypoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
import {DEFAULT_SKIM_OPTIONS, pubcode} from './constants';
import {Waypoint} from '../waypoint';
import {XCUST_ATTRIBUTE_NAME} from '../constants';
import {parseQueryString, parseUrlDeprecated} from '../../../../src/url';
import {parseQueryString} from '../../../../src/core/types/string/url';
import {parseUrlDeprecated} from '../../../../src/url';
import helpersFactory from './helpers';

describes.fakeWin(
Expand Down
3 changes: 2 additions & 1 deletion extensions/amp-social-share/0.1/amp-social-share.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
import {CSS} from '../../../build/amp-social-share-0.1.css';
import {Keys} from '../../../src/core/constants/key-codes';
import {Services} from '../../../src/services';
import {addParamsToUrl, parseQueryString} from '../../../src/url';
import {addParamsToUrl} from '../../../src/url';
import {dev, devAssert, user, userAssert} from '../../../src/log';
import {dict} from '../../../src/core/types/object';
import {getDataParamsFromAttributes, openWindowDialog} from '../../../src/dom';
import {getSocialConfig} from './amp-social-share-config';
import {parseQueryString} from '../../../src/core/types/string/url';
import {toggle} from '../../../src/style';

const TAG = 'amp-social-share';
Expand Down
3 changes: 2 additions & 1 deletion extensions/amp-social-share/1.0/amp-social-share.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ import {Layout} from '../../../src/layout';
import {PreactBaseElement} from '../../../src/preact/base-element';
import {Services} from '../../../src/services';
import {SocialShare} from './social-share';
import {addParamsToUrl, parseQueryString} from '../../../src/url';
import {addParamsToUrl} from '../../../src/url';
import {dict} from '../../../src/core/types/object';
import {getDataParamsFromAttributes} from '../../../src/dom';
import {getSocialConfig} from './social-share-config';
import {isExperimentOn} from '../../../src/experiments';
import {parseQueryString} from '../../../src/core/types/string/url';
import {toWin} from '../../../src/types';
import {toggle} from '../../../src/style';
import {userAssert} from '../../../src/log';
Expand Down
3 changes: 2 additions & 1 deletion extensions/amp-social-share/1.0/social-share.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ import * as Preact from '../../../src/preact';
import {Keys} from '../../../src/core/constants/key-codes';
import {SocialShareIcon} from './social-share-svgs';
import {Wrapper} from '../../../src/preact/component';
import {addParamsToUrl, parseQueryString} from '../../../src/url';
import {addParamsToUrl} from '../../../src/url';
import {dict} from '../../../src/core/types/object';
import {getSocialConfig} from './social-share-config';
import {openWindowDialog} from '../../../src/dom';
import {parseQueryString} from '../../../src/core/types/string/url';
import {useResourcesNotify} from '../../../src/preact/utils';
import {useStyles} from './social-share.jss';

Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-story-dev-tools/0.1/amp-story-dev-tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
} from './amp-story-dev-tools-tab-preview';
import {CSS} from '../../../build/amp-story-dev-tools-0.1.css';
import {htmlFor} from '../../../src/static-template';
import {parseQueryString} from '../../../src/url';
import {parseQueryString} from '../../../src/core/types/string/url';
import {toggle} from '../../../src/style';
import {updateHash} from './utils';

Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-story-dev-tools/0.1/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import {parseQueryString} from '../../../src/url';
import {parseQueryString} from '../../../src/core/types/string/url';

/**
* Updates the hashString with the dictionary<string, string> passed in
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-story/1.0/amp-story.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ import {getMode} from '../../../src/mode';
import {getState} from '../../../src/history';
import {isExperimentOn} from '../../../src/experiments';
import {isPageAttachmentUiV2ExperimentOn} from './amp-story-page-attachment-ui-v2';
import {parseQueryString} from '../../../src/url';
import {parseQueryString} from '../../../src/core/types/string/url';
import {
removeAttributeInMutate,
setAttributeInMutate,
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-story/1.0/embed-mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/
import {isEnumValue} from '../../../src/core/types';
import {parseQueryString} from '../../../src/url';
import {parseQueryString} from '../../../src/core/types/string/url';

/**
* Embed mode for AMP story. See ../embed-modes.md for details.
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-story/1.0/prerender-active-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import {escapeCssSelectorIdent} from '../../../src/core/dom/css';
import {parseQueryString} from '../../../src/url';
import {parseQueryString} from '../../../src/core/types/string/url';
import {toWin} from '../../../src/types';

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,13 @@ import {Services} from '../../../src/services';
import {SubscriptionsScoreFactor} from '../../amp-subscriptions/0.1/constants.js';
import {UrlBuilder} from '../../amp-subscriptions/0.1/url-builder';
import {WindowInterface} from '../../../src/window-interface';
import {
assertHttpsUrl,
parseQueryString,
parseUrlDeprecated,
} from '../../../src/url';
import {assertHttpsUrl, parseUrlDeprecated} from '../../../src/url';
import {experimentToggles, isExperimentOn} from '../../../src/experiments';
import {getData} from '../../../src/event-helper';
import {getMode} from '../../../src/mode';
import {getValueForExpr} from '../../../src/core/types/object';
import {installStylesForDoc} from '../../../src/style-installer';
import {parseQueryString} from '../../../src/core/types/string/url';

import {devAssert, user, userAssert} from '../../../src/log';

Expand Down
3 changes: 2 additions & 1 deletion extensions/amp-subscriptions/0.1/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
*/

import {ActionStatus} from './analytics';
import {assertHttpsUrl, parseQueryString} from '../../../src/url';
import {assertHttpsUrl} from '../../../src/url';
import {dev, userAssert} from '../../../src/log';
import {dict} from '../../../src/core/types/object';
import {openLoginDialog} from '../../amp-access/0.1/login-dialog';
import {parseQueryString} from '../../../src/core/types/string/url';

const TAG = 'amp-subscriptions';
const LOCAL = 'local';
Expand Down
Loading

0 comments on commit 7478045

Please sign in to comment.