diff --git a/js/privatebin.js b/js/privatebin.js
index 4fd0e99..8b98ba8 100644
--- a/js/privatebin.js
+++ b/js/privatebin.js
@@ -136,7 +136,7 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
setMessage: function(element, message)
{
var content = element.contents();
- if (content.length > 0)
+ if (content.length > 1)
{
content[content.length - 1].nodeValue = ' ' + message;
}
diff --git a/js/test.js b/js/test.js
index 93e7a8c..7906743 100644
--- a/js/test.js
+++ b/js/test.js
@@ -77,7 +77,7 @@ describe('helper', function () {
var html = '',
result = true;
ids.forEach(function(item, i) {
- html += '
' + (contents[i] || contents[0]) + '
';
+ html += '' + $.PrivateBin.helper.htmlEntities(contents[i] || contents[0]) + '
';
});
var clean = jsdom(html);
ids.forEach(function(item, i) {
@@ -102,7 +102,7 @@ describe('helper', function () {
var html = '',
result = true;
ids.forEach(function(item, i) {
- html += '' + (contents[i] || contents[0]) + '
';
+ html += '' + $.PrivateBin.helper.htmlEntities(contents[i] || contents[0]) + '
';
});
var clean = jsdom(html);
ids.forEach(function(item, i) {
@@ -117,6 +117,54 @@ describe('helper', function () {
);
});
+ describe('setMessage', function () {
+ jsc.property(
+ 'replaces the content of an empty element, analog to setElementText',
+ jsc.nearray(jsc.nearray(jsc.elements(alnumString))),
+ 'nearray string',
+ 'string',
+ function (ids, contents, replacingContent) {
+ var html = '',
+ result = true;
+ ids.forEach(function(item, i) {
+ html += '' + $.PrivateBin.helper.htmlEntities(contents[i] || contents[0]) + '
';
+ });
+ var clean = jsdom(html);
+ ids.forEach(function(item, i) {
+ var id = item.join(''),
+ element = $(document.getElementById(id));
+ $.PrivateBin.helper.setMessage(element, replacingContent);
+ result *= replacingContent === $(document.getElementById(id)).text();
+ });
+ clean();
+ return Boolean(result);
+ }
+ );
+ jsc.property(
+ 'replaces the last child of a non-empty element',
+ jsc.nearray(jsc.nearray(jsc.elements(alnumString))),
+ jsc.nearray(jsc.nearray(jsc.elements(alnumString))),
+ 'nearray string',
+ 'string',
+ function (ids, classes, contents, replacingContent) {
+ var html = '',
+ result = true;
+ ids.forEach(function(item, i) {
+ html += ' ' + $.PrivateBin.helper.htmlEntities(contents[i] || contents[0]) + '
';
+ });
+ var clean = jsdom(html);
+ ids.forEach(function(item, i) {
+ var id = item.join(''),
+ element = $(document.getElementById(id));
+ $.PrivateBin.helper.setMessage(element, replacingContent);
+ result *= ' ' + replacingContent === $(document.getElementById(id)).contents()[1].nodeValue;
+ });
+ clean();
+ return Boolean(result);
+ }
+ );
+ });
+
describe('scriptLocation', function () {
jsc.property(
'returns the URL without query & fragment',
diff --git a/tpl/bootstrap.php b/tpl/bootstrap.php
index 60c6727..50f203b 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 c92136f..88af3aa 100644
--- a/tpl/page.php
+++ b/tpl/page.php
@@ -47,7 +47,7 @@ if ($MARKDOWN):
-
+