mirror of
https://github.com/PrivateBin/PrivateBin.git
synced 2024-03-22 13:10:41 +08:00
added test for urls2links function, fixing bug - asterisk is allowed in URLs query string
This commit is contained in:
parent
b992bcc732
commit
b00bcd1352
|
@ -164,13 +164,13 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
|
|||
var markup = '<a href="$1" rel="nofollow">$1</a>';
|
||||
element.html(
|
||||
element.html().replace(
|
||||
/((http|https|ftp):\/\/[\w?=&.\/-;#@~%+-]+(?![\w\s?&.\/;#~%"=-]*>))/ig,
|
||||
/((http|https|ftp):\/\/[\w?=&.\/-;#@~%+*-]+(?![\w\s?&.\/;#~%"=-]*>))/ig,
|
||||
markup
|
||||
)
|
||||
);
|
||||
element.html(
|
||||
element.html().replace(
|
||||
/((magnet):[\w?=&.\/-;#@~%+-]+)/ig,
|
||||
/((magnet):[\w?=&.\/-;#@~%+*-]+)/ig,
|
||||
markup
|
||||
)
|
||||
);
|
||||
|
|
58
js/test.js
58
js/test.js
|
@ -165,6 +165,64 @@ describe('helper', function () {
|
|||
);
|
||||
});
|
||||
|
||||
describe('urls2links', function () {
|
||||
jsc.property(
|
||||
'ignores non-URL content',
|
||||
'string',
|
||||
function (content) {
|
||||
var element = $('<div>' + content + '</div>'),
|
||||
before = element.html();
|
||||
$.PrivateBin.helper.urls2links(element);
|
||||
return before === element.html();
|
||||
}
|
||||
);
|
||||
jsc.property(
|
||||
'replaces URLs with anchors',
|
||||
'string',
|
||||
jsc.elements(['http', 'https', 'ftp']),
|
||||
jsc.nearray(jsc.elements(a2zString)),
|
||||
jsc.array(jsc.elements(queryString)),
|
||||
jsc.array(jsc.elements(queryString)),
|
||||
'string',
|
||||
function (prefix, schema, address, query, fragment, postfix) {
|
||||
var query = query.join(''),
|
||||
fragment = fragment.join(''),
|
||||
url = schema + '://' + address.join('') + '/?' + query + '#' + fragment,
|
||||
prefix = $.PrivateBin.helper.htmlEntities(prefix),
|
||||
postfix = ' ' + $.PrivateBin.helper.htmlEntities(postfix),
|
||||
element = $('<div>' + prefix + url + postfix + '</div>');
|
||||
|
||||
// special cases: When the query string and fragment imply the beginning of an HTML entity, eg. � or &#x
|
||||
if (
|
||||
query.slice(-1) === '&' &&
|
||||
(parseInt(fragment.substring(0, 1), 10) >= 0 || fragment.charAt(0) === 'x' )
|
||||
)
|
||||
{
|
||||
url = schema + '://' + address.join('') + '/?' + query.substring(0, query.length - 1);
|
||||
postfix = '';
|
||||
element = $('<div>' + prefix + url + '</div>');
|
||||
}
|
||||
|
||||
$.PrivateBin.helper.urls2links(element);
|
||||
return element.html() === $('<div>' + prefix + '<a href="' + url + '" rel="nofollow">' + url + '</a>' + postfix + '</div>').html();
|
||||
}
|
||||
);
|
||||
jsc.property(
|
||||
'replaces magnet links with anchors',
|
||||
'string',
|
||||
jsc.array(jsc.elements(queryString)),
|
||||
'string',
|
||||
function (prefix, query, postfix) {
|
||||
var url = 'magnet:?' + query.join(''),
|
||||
prefix = $.PrivateBin.helper.htmlEntities(prefix),
|
||||
postfix = $.PrivateBin.helper.htmlEntities(postfix),
|
||||
element = $('<div>' + prefix + url + ' ' + postfix + '</div>');
|
||||
$.PrivateBin.helper.urls2links(element);
|
||||
return element.html() === $('<div>' + prefix + '<a href="' + url + '" rel="nofollow">' + url + '</a> ' + postfix + '</div>').html();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
describe('scriptLocation', function () {
|
||||
jsc.property(
|
||||
'returns the URL without query & fragment',
|
||||
|
|
|
@ -69,7 +69,7 @@ if ($MARKDOWN):
|
|||
<?php
|
||||
endif;
|
||||
?>
|
||||
<script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-2ux6N+vpaJF7Gal63ZMJCdcOsQsaNcMbZwRqh+/pwAH5N6ZpEPgN5LiOGHVGGcna4Cut4veXu7lfRa8ZqEzHkw==" crossorigin="anonymous"></script>
|
||||
<script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-2xPbJySqwLEOH/wTiKWSsMT1qZnHkELGrRwKNGeNxfFnssFH7u3GtNKeccu5SB4+2Lctpd1Bt6vphTRWGi5+cw==" crossorigin="anonymous"></script>
|
||||
<!--[if lt IE 10]>
|
||||
<style type="text/css">body {padding-left:60px;padding-right:60px;} #ienotice {display:block;} #oldienotice {display:block;}</style>
|
||||
<![endif]-->
|
||||
|
|
|
@ -47,7 +47,7 @@ if ($MARKDOWN):
|
|||
<?php
|
||||
endif;
|
||||
?>
|
||||
<script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-2ux6N+vpaJF7Gal63ZMJCdcOsQsaNcMbZwRqh+/pwAH5N6ZpEPgN5LiOGHVGGcna4Cut4veXu7lfRa8ZqEzHkw==" crossorigin="anonymous"></script>
|
||||
<script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-2xPbJySqwLEOH/wTiKWSsMT1qZnHkELGrRwKNGeNxfFnssFH7u3GtNKeccu5SB4+2Lctpd1Bt6vphTRWGi5+cw==" crossorigin="anonymous"></script>
|
||||
<!--[if lt IE 10]>
|
||||
<style type="text/css">body {padding-left:60px;padding-right:60px;} #ienotice {display:block;} #oldienotice {display:block;}</style>
|
||||
<![endif]-->
|
||||
|
|
Loading…
Reference in New Issue
Block a user