From c74858b1981b51c57c292eb6cea12a293128c5ed Mon Sep 17 00:00:00 2001 From: Seyi Adebajo Date: Mon, 1 May 2017 11:33:40 -0700 Subject: [PATCH] fixes navigating to datasets from rail: numbers were previously excluded from parsed string. DRY's urn regex --- .../browser/containers/browser-rail.js | 17 ++++++----------- wherehows-web/app/utils/validators/urn.js | 4 ++-- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/wherehows-web/app/components/browser/containers/browser-rail.js b/wherehows-web/app/components/browser/containers/browser-rail.js index 7c786b5f36..81f749465e 100644 --- a/wherehows-web/app/components/browser/containers/browser-rail.js +++ b/wherehows-web/app/components/browser/containers/browser-rail.js @@ -1,5 +1,6 @@ import Ember from 'ember'; import connect from 'ember-redux/components/connect'; +import { urnRegex } from 'wherehows-web/utils/validators/urn'; const { Component } = Ember; @@ -10,19 +11,12 @@ const { Component } = Ember; */ const pageRegex = /\/page\/([0-9]+)/i; /** - * Matches a url string with a `urn` query. urn query starts with letters or underscore segment of any length greater - * than 1 followed by colon and 3 forward slashes and a segment containing letters, _ or /, or none - * The value following the urn key is retained - * @type {RegExp} - */ -const urnRegex = /urn=([a-z_]+[:\/]{3}[a-z_\/]*)/i; -/** - * Matches a url string path segment that optionally starts with a hash followed by forward slash, at least one - * alphabet, forward slash, number of varying length and optional trailing slash + * Matches a url string path segment that optionally starts with a hash followed by forward slash, + * either datasets or flows or metrics, forward slash, number of varying length and optional trailing slash * The number is retained * @type {RegExp} */ -const entityRegex = /^#?\/[a-z]+\/([0-9]+)\/?/i; +const entityRegex = /^#?\/(?:datasets|metrics|flows)\/([0-9]+)\/?/; /** * Takes a node url and parses out the query params and path spec to be included in the link component @@ -46,7 +40,8 @@ const nodeUrlToQueryParams = nodeUrl => { // If we have a urn match, append the urn to eventual query params object if (Array.isArray(urnMatch)) { queryParams = Object.assign({}, queryParams, { - urn: urnMatch[1] + // Extract the entire match as urn value + urn: urnMatch[0] }); } diff --git a/wherehows-web/app/utils/validators/urn.js b/wherehows-web/app/utils/validators/urn.js index 7e854d85ac..f22ef6a1b4 100644 --- a/wherehows-web/app/utils/validators/urn.js +++ b/wherehows-web/app/utils/validators/urn.js @@ -1,10 +1,10 @@ /** - * Matches a url string with a `urn` query. urn query starts with letters or underscore segment of any length greater + * Matches a url string with a `urn` query. urn query with letters or underscore segment of any length greater * than 1 followed by colon and 3 forward slashes and a segment containing letters, _ or /, or none * The value following the urn key is retained * @type {RegExp} */ -const urnRegex = /^([a-z_]+):\/{3}([a-z_\-\/]*)/i; +const urnRegex = /([a-z_]+):\/{3}([a-z0-9_\-\/]*)/i; /** * Asserts that a provided string matches the urn pattern above * @param {String} candidateUrn the string to test on