making use of the URL object in the existing tests

This commit is contained in:
El RIDO 2019-06-20 22:30:49 +02:00
parent 1958a55651
commit 50cc6995e0
No known key found for this signature in database
GPG key ID: 0F5C940A6BD81F92
5 changed files with 17 additions and 25 deletions

View file

@ -5,7 +5,7 @@ global.assert = require('assert');
global.jsc = require('jsverify'); global.jsc = require('jsverify');
global.jsdom = require('jsdom-global'); global.jsdom = require('jsdom-global');
global.cleanup = global.jsdom(); global.cleanup = global.jsdom();
global.window.URL = require('jsdom-url'); global.URL = require('jsdom-url').URL;
global.fs = require('fs'); global.fs = require('fs');
global.WebCrypto = require('node-webcrypto-ossl'); global.WebCrypto = require('node-webcrypto-ossl');

View file

@ -1196,8 +1196,6 @@ jQuery.PrivateBin = (function($, RawDeflate) {
} }
// do use URL interface, if possible // do use URL interface, if possible
if (window.URL && window.URL.prototype && ('searchParams' in window.URL.prototype)) {
try {
const url = new URL(window.location); const url = new URL(window.location);
for (const param of url.searchParams) { for (const param of url.searchParams) {
@ -1207,19 +1205,11 @@ jQuery.PrivateBin = (function($, RawDeflate) {
if (value === '' && idRegEx.test(key)) { if (value === '' && idRegEx.test(key)) {
// safe, as the whole regex is matched // safe, as the whole regex is matched
id = key; id = key;
return id; return key;
}
}
} catch (e) {
// fallback below
console.error('URL interface not properly supported, error:', e);
} }
} }
// Attention: This also returns the delete token inside of the ID, if it is specified if (id === null) {
id = (window.location.search.match(idRegExFind) || [''])[0];
if (id === '') {
throw 'no paste id given'; throw 'no paste id given';
} }
@ -4587,7 +4577,7 @@ jQuery.PrivateBin = (function($, RawDeflate) {
*/ */
function isInsecureConnection() function isInsecureConnection()
{ {
const url = new URL(document.URL); const url = new URL(window.location);
// HTTP is obviously insecure // HTTP is obviously insecure
if (url.protocol !== 'http:') { if (url.protocol !== 'http:') {

View file

@ -93,8 +93,9 @@ describe('Model', function () {
clean = jsdom('', { clean = jsdom('', {
url: schema.join('') + '://' + address.join('') + url: schema.join('') + '://' + address.join('') +
'/?' + queryString + '#' + fragment '/?' + queryString + '#' + fragment
}), });
result = $.PrivateBin.Model.getPasteId(); global.URL = require('jsdom-url').URL;
var result = $.PrivateBin.Model.getPasteId();
$.PrivateBin.Model.reset(); $.PrivateBin.Model.reset();
clean(); clean();
return pasteIdString === result; return pasteIdString === result;
@ -111,6 +112,7 @@ describe('Model', function () {
'/#' + fragment '/#' + fragment
}), }),
result = false; result = false;
global.URL = require('jsdom-url').URL;
try { try {
$.PrivateBin.Model.getPasteId(); $.PrivateBin.Model.getPasteId();
} }

View file

@ -72,7 +72,7 @@ if ($MARKDOWN):
endif; endif;
?> ?>
<script type="text/javascript" data-cfasync="false" src="js/purify-1.0.10.js" integrity="sha512-CqskSFXERL38A1PJP9BlO04me7kmwgDIhN1+k24RoFiisEwXA0BMdm0lzJC7g5jCRZ4k5OYdOJGEqW9CwDl4CA==" crossorigin="anonymous"></script> <script type="text/javascript" data-cfasync="false" src="js/purify-1.0.10.js" integrity="sha512-CqskSFXERL38A1PJP9BlO04me7kmwgDIhN1+k24RoFiisEwXA0BMdm0lzJC7g5jCRZ4k5OYdOJGEqW9CwDl4CA==" crossorigin="anonymous"></script>
<script type="text/javascript" data-cfasync="false" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-GrZx46UtJMOVLWWM6lYoTCnrdLM1EvNps1yUI12PvhcIYpe4WfOrIwmNVjngz2OZhkNj8xvidH9NCovCobpoNQ==" crossorigin="anonymous"></script> <script type="text/javascript" data-cfasync="false" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-sVyyVYPT9SWHwzqnG3KVpxDVDCQVE3Rb3xxe3aaXxMLPvsqzZSS/WnviVLzdT0K8hCeO2bqNLymW/5POz1u11w==" crossorigin="anonymous"></script>
<!--[if IE]> <!--[if IE]>
<style type="text/css">body {padding-left:60px;padding-right:60px;} #ienotice {display:block;}</style> <style type="text/css">body {padding-left:60px;padding-right:60px;} #ienotice {display:block;}</style>
<![endif]--> <![endif]-->

View file

@ -50,7 +50,7 @@ if ($MARKDOWN):
endif; endif;
?> ?>
<script type="text/javascript" data-cfasync="false" src="js/purify-1.0.10.js" integrity="sha512-CqskSFXERL38A1PJP9BlO04me7kmwgDIhN1+k24RoFiisEwXA0BMdm0lzJC7g5jCRZ4k5OYdOJGEqW9CwDl4CA==" crossorigin="anonymous"></script> <script type="text/javascript" data-cfasync="false" src="js/purify-1.0.10.js" integrity="sha512-CqskSFXERL38A1PJP9BlO04me7kmwgDIhN1+k24RoFiisEwXA0BMdm0lzJC7g5jCRZ4k5OYdOJGEqW9CwDl4CA==" crossorigin="anonymous"></script>
<script type="text/javascript" data-cfasync="false" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-GrZx46UtJMOVLWWM6lYoTCnrdLM1EvNps1yUI12PvhcIYpe4WfOrIwmNVjngz2OZhkNj8xvidH9NCovCobpoNQ==" crossorigin="anonymous"></script> <script type="text/javascript" data-cfasync="false" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-sVyyVYPT9SWHwzqnG3KVpxDVDCQVE3Rb3xxe3aaXxMLPvsqzZSS/WnviVLzdT0K8hCeO2bqNLymW/5POz1u11w==" crossorigin="anonymous"></script>
<!--[if IE]> <!--[if IE]>
<style type="text/css">body {padding-left:60px;padding-right:60px;} #ienotice {display:block;}</style> <style type="text/css">body {padding-left:60px;padding-right:60px;} #ienotice {display:block;}</style>
<![endif]--> <![endif]-->