Merge pull request #1114 from cptran777/encoded-wildcard-in-datasets

Encode wildcard symbol before sending api call for readdataset
This commit is contained in:
Charlie Tran 2018-04-23 22:57:56 -07:00 committed by GitHub
commit d59d88b6a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 2 deletions

View File

@ -6,7 +6,13 @@ import ComputedProperty from '@ember/object/computed';
import Configurator from 'wherehows-web/services/configurator'; import Configurator from 'wherehows-web/services/configurator';
import Notifications, { NotificationEvent } from 'wherehows-web/services/notifications'; import Notifications, { NotificationEvent } from 'wherehows-web/services/notifications';
import { refreshModelQueryParams } from 'wherehows-web/utils/helpers/routes'; import { refreshModelQueryParams } from 'wherehows-web/utils/helpers/routes';
import isUrn, { convertWhUrnToLiUrn, decodeUrn, isLiUrn, isWhUrn } from 'wherehows-web/utils/validators/urn'; import isUrn, {
convertWhUrnToLiUrn,
decodeUrn,
isLiUrn,
isWhUrn,
encodeWildcard
} from 'wherehows-web/utils/validators/urn';
import { datasetIdToUrn, readDatasetByUrn } from 'wherehows-web/utils/api/datasets/dataset'; import { datasetIdToUrn, readDatasetByUrn } from 'wherehows-web/utils/api/datasets/dataset';
import { IDatasetView } from 'wherehows-web/typings/api/datasets/dataset'; import { IDatasetView } from 'wherehows-web/typings/api/datasets/dataset';
import DatasetController from 'wherehows-web/controllers/datasets/dataset'; import DatasetController from 'wherehows-web/controllers/datasets/dataset';
@ -57,7 +63,7 @@ export default class DatasetRoute extends Route {
} }
if (isLiUrn(decodeUrn(resolvedUrn))) { if (isLiUrn(decodeUrn(resolvedUrn))) {
return await readDatasetByUrn(resolvedUrn); return await readDatasetByUrn(encodeWildcard(resolvedUrn));
} }
get(this, 'notifications').notify(NotificationEvent.error, { get(this, 'notifications').notify(NotificationEvent.error, {

View File

@ -119,6 +119,33 @@ const encodeForwardSlash = (urn: string): string => urn.replace(/\//g, encodeURI
*/ */
const decodeForwardSlash = (urn: string): string => urn.replace(encodedSlashRegExp, decodeURIComponent('/')); const decodeForwardSlash = (urn: string): string => urn.replace(encodedSlashRegExp, decodeURIComponent('/'));
/**
* Stores the encoded URL for the asterisk/wildcard symbol since encodeURIComponent doesn't catch these
* as a reserved symbol
* @type {string}
*/
const encodedWildcard = '%2A';
/**
* Cached RegExp object for a global search of /
* @type {RegExp}
*/
const encodedWildcardRegExp = new RegExp(encodedWildcard, 'g');
/**
* Replaces any occurence of * with the encoded equivalent
* @param {string} urn
* @return {string}
*/
const encodeWildcard = (urn: string): string => urn.replace(/\*/g, encodedWildcard);
/**
* Replaces encoded slashes with /
* @param {string} urn
* @return {string}
*/
const decodeWildcard = (urn: string): string => urn.replace(encodedWildcardRegExp, decodeURIComponent('*'));
/** /**
* Replaces occurrences of / with the encoded counterpart in a urn string * Replaces occurrences of / with the encoded counterpart in a urn string
* @param {string} urn * @param {string} urn
@ -146,6 +173,8 @@ export {
convertWhUrnToLiUrn, convertWhUrnToLiUrn,
convertWhDatasetPathToLiPath, convertWhDatasetPathToLiPath,
encodeForwardSlash, encodeForwardSlash,
encodeWildcard,
decodeWildcard,
encodeUrn, encodeUrn,
decodeUrn decodeUrn
}; };