From b6d8d0f250a17d6796b1eb42871aec023ba5b27a Mon Sep 17 00:00:00 2001 From: El RIDO Date: Mon, 6 Mar 2017 19:48:07 +0100 Subject: [PATCH] found problem with unit test of baseUri function, makes code much simpler --- js/privatebin.js | 16 +--------------- js/test.js | 8 +++++--- tpl/bootstrap.php | 2 +- tpl/page.php | 2 +- 4 files changed, 8 insertions(+), 20 deletions(-) diff --git a/js/privatebin.js b/js/privatebin.js index 573ec9f..f43e334 100644 --- a/js/privatebin.js +++ b/js/privatebin.js @@ -276,21 +276,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) { return baseUri; } - // window.baseURI isn't emulated by JSdom - var loc = window.location; - baseUri = loc.href.substring( - 0, - loc.href.length - loc.search.length - loc.hash.length - ); - - // if base uri contains query string (when no base tag is present), - // it is unwanted - var queryIndex = baseUri.indexOf('?'); - if (queryIndex !== -1) { - // so we built our own baseuri - baseUri = baseUri.substring(0, queryIndex); - } - + baseUri = window.location.origin + window.location.pathname; return baseUri; } diff --git a/js/test.js b/js/test.js index 31da19f..e83d43b 100644 --- a/js/test.js +++ b/js/test.js @@ -11,7 +11,9 @@ var jsc = require('jsverify'), a2zString.map(function(c) { return c.toUpperCase(); }) - ); + ), + // schemas supported by the whatwg-url library + schemas = ['ftp','gopher','http','https','ws','wss']; global.$ = global.jQuery = require('./jquery-3.1.1'); global.sjcl = require('./sjcl-1.0.6'); @@ -73,12 +75,12 @@ describe('Helper', function () { jsc.property( 'returns the URL without query & fragment', - jsc.nearray(jsc.elements(a2zString)), + jsc.elements(schemas), jsc.nearray(jsc.elements(a2zString)), jsc.array(jsc.elements(queryString)), 'string', function (schema, address, query, fragment) { - var expected = schema.join('') + '://' + address.join('') + '/', + var expected = schema + '://' + address.join('') + '/', clean = jsdom('', {url: expected + '?' + query.join('') + '#' + fragment}), result = $.PrivateBin.Helper.baseUri(); $.PrivateBin.Helper.reset(); diff --git a/tpl/bootstrap.php b/tpl/bootstrap.php index 0c0e51c..4dd6389 100644 --- a/tpl/bootstrap.php +++ b/tpl/bootstrap.php @@ -69,7 +69,7 @@ if ($MARKDOWN): - + diff --git a/tpl/page.php b/tpl/page.php index 25db1e5..8ea25d7 100644 --- a/tpl/page.php +++ b/tpl/page.php @@ -47,7 +47,7 @@ if ($MARKDOWN): - +