This is an automated email from the ASF dual-hosted git repository.

garren pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/couchdb-fauxton.git


The following commit(s) were added to refs/heads/master by this push:
     new 3001db3  Replication page renders even with missing URL (#1004)
3001db3 is described below

commit 3001db3edeb0f582ee361efd27ef3e7ececc6c7b
Author: garren smith <[email protected]>
AuthorDate: Tue Oct 24 08:55:28 2017 +0200

    Replication page renders even with missing URL (#1004)
    
    Handle bad/missing urls by ignoring them in the formatUrl function
---
 app/addons/replication/__tests__/common-table.test.js |  5 +++++
 app/addons/replication/components/common-table.js     | 11 +++++++++--
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/app/addons/replication/__tests__/common-table.test.js 
b/app/addons/replication/__tests__/common-table.test.js
index d7850e1..ab8870f 100644
--- a/app/addons/replication/__tests__/common-table.test.js
+++ b/app/addons/replication/__tests__/common-table.test.js
@@ -16,6 +16,7 @@ import {formatUrl} from '../components/common-table';
 const {assert}  = utils;
 
 describe('Common Table Component', () => {
+
   describe("formatUrl", () => {
     it("renders a url with tricky password characters", () => {
       const url = "http://hello:h#$!^@couchdb.com/my-db";;
@@ -28,5 +29,9 @@ describe('Common Table Component', () => {
       const el = shallow(formatUrl(url));
       assert.equal(el.find('a').prop('href'), '#/database/my-db/_all_docs');
     });
+
+    it('renders a with a default url if no url is supplied', () => {
+      assert.equal(formatUrl(), '');
+    });
   });
 });
diff --git a/app/addons/replication/components/common-table.js 
b/app/addons/replication/components/common-table.js
index 80d0934..8e3fd05 100644
--- a/app/addons/replication/components/common-table.js
+++ b/app/addons/replication/components/common-table.js
@@ -18,8 +18,15 @@ import {ErrorModal} from './modals';
 import {removeCredentialsFromUrl} from '../api';
 
 export const formatUrl = (url) => {
-  const urlObj = new URL(removeCredentialsFromUrl(url));
-  const encoded = encodeURIComponent(urlObj.pathname.slice(1));
+  let urlObj;
+  let encoded;
+  try {
+    urlObj = new URL(removeCredentialsFromUrl(url));
+    encoded = encodeURIComponent(urlObj.pathname.slice(1));
+  } catch (error) {
+    console.log('error with url', url);
+    return '';
+  }
 
   if (url.indexOf(window.location.hostname) > -1) {
     return (

-- 
To stop receiving notification emails like this one, please contact
['"[email protected]" <[email protected]>'].

Reply via email to