mirror of
https://github.com/datahub-project/datahub.git
synced 2025-08-30 20:15:56 +00:00
Merge pull request #1114 from cptran777/encoded-wildcard-in-datasets
Encode wildcard symbol before sending api call for readdataset
This commit is contained in:
commit
d59d88b6a7
@ -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, {
|
||||||
|
@ -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
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user