Ox.parseHTML -> Ox.sanitizeHTML, Ox.encodeHTML -> Ox.encodeHTMLEntities, Ox.decodeHTML -> Ox.decodeHTMLEntities

This commit is contained in:
rolux 2012-05-27 12:40:02 +02:00
parent fef07dff6f
commit c41afd2f5d
9 changed files with 28 additions and 26 deletions

View file

@ -606,9 +606,9 @@ Ox.ListCalendar = function(options, self) {
function decodeValues(place) { function decodeValues(place) {
return Ox.map(place, function(value) { return Ox.map(place, function(value) {
return Ox.isString(value) ? Ox.decodeHTML(value) return Ox.isString(value) ? Ox.decodeHTMLEntities(value)
: Ox.isArray(value) ? Ox.map(value, function(value) { : Ox.isArray(value) ? Ox.map(value, function(value) {
return Ox.decodeHTML(value); return Ox.decodeHTMLEntities(value);
}) })
: value; : value;
}); });
@ -632,9 +632,9 @@ Ox.ListCalendar = function(options, self) {
function encodeValues(place) { function encodeValues(place) {
return Ox.map(place, function(value) { return Ox.map(place, function(value) {
return Ox.isString(value) ? Ox.encodeHTML(value) return Ox.isString(value) ? Ox.encodeHTMLEntities(value)
: Ox.isArray(value) ? Ox.map(value, function(value) { : Ox.isArray(value) ? Ox.map(value, function(value) {
return Ox.encodeHTML(value); return Ox.encodeHTMLEntities(value);
}) })
: value; : value;
}); });

View file

@ -88,7 +88,7 @@ Ox.DocPage = function(options, self) {
'<code><b>' + (name || item.name) + '</b> ' '<code><b>' + (name || item.name) + '</b> '
+ '&lt;' + item.types.join('&gt;</code> or <code>&lt;') + '&gt; </code>' + '&lt;' + item.types.join('&gt;</code> or <code>&lt;') + '&gt; </code>'
+ (item['default'] ? '(default: <code>' + item['default'] + '</code>) ' : '') + (item['default'] ? '(default: <code>' + item['default'] + '</code>) ' : '')
+ Ox.parseHTML(item.summary) + Ox.sanitizeHTML(item.summary)
) )
]; ];
[ [
@ -105,7 +105,7 @@ Ox.DocPage = function(options, self) {
marginTop: (level ? 0 : 8) + 'px', marginTop: (level ? 0 : 8) + 'px',
marginLeft: (level * 32) + 'px' marginLeft: (level * 32) + 'px'
}) })
.html(Ox.parseHTML(item.description)) .html(Ox.sanitizeHTML(item.description))
); );
} else { } else {
$elements.push($('<div>') $elements.push($('<div>')
@ -160,7 +160,7 @@ Ox.DocPage = function(options, self) {
.css({marginLeft: (level * 32 + 16) + 'px'}) .css({marginLeft: (level * 32 + 16) + 'px'})
.html( .html(
'<code><b>&gt;&nbsp;' '<code><b>&gt;&nbsp;'
+ Ox.encodeHTML(example.statement) + Ox.encodeHTMLEntities(example.statement)
.replace(/ /g, '&nbsp;') .replace(/ /g, '&nbsp;')
.replace(/\n/g, '<br/>\n&nbsp;&nbsp;') .replace(/\n/g, '<br/>\n&nbsp;&nbsp;')
+ '</b></code>' + '</b></code>'
@ -170,7 +170,7 @@ Ox.DocPage = function(options, self) {
.addClass(className) .addClass(className)
.css({marginLeft: (level * 32 + 16) + 'px'}) .css({marginLeft: (level * 32 + 16) + 'px'})
.html( .html(
'<code>' + Ox.encodeHTML(example.result) + '</code>' '<code>' + Ox.encodeHTMLEntities(example.result) + '</code>'
) )
) )
}); });

View file

@ -71,7 +71,7 @@ Ox.SyntaxHighlighter = function(options, self) {
} }
} }
source += '<span class="' + classNames + '">' + source += '<span class="' + classNames + '">' +
Ox.encodeHTML(token.value) Ox.encodeHTMLEntities(token.value)
.replace(/ /g, whitespace) .replace(/ /g, whitespace)
.replace(/\t/g, tab) .replace(/\t/g, tab)
.replace(/\n/g, linebreak) + '</span>'; .replace(/\n/g, linebreak) + '</span>';

View file

@ -155,7 +155,7 @@ Ox.Editable = function(options, self) {
} }
function formatInputValue() { function formatInputValue() {
return Ox.decodeHTML( return Ox.decodeHTMLEntities(
self.options.type == 'input' self.options.type == 'input'
? self.options.value ? self.options.value
: self.options.value.replace(/<br\/?><br\/?>/g, '\n\n') : self.options.value.replace(/<br\/?><br\/?>/g, '\n\n')
@ -163,7 +163,7 @@ Ox.Editable = function(options, self) {
} }
function formatTestValue() { function formatTestValue() {
var value = Ox.encodeHTML(self.$input.options('value')); var value = Ox.encodeHTMLEntities(self.$input.options('value'));
return !value ? '&nbsp;' return !value ? '&nbsp;'
: self.options.type == 'input' : self.options.type == 'input'
? value.replace(/ /g, '&nbsp;') ? value.replace(/ /g, '&nbsp;')
@ -181,7 +181,7 @@ Ox.Editable = function(options, self) {
value = self.options.format(self.options.value) value = self.options.format(self.options.value)
} }
if (self.options.highlight) { if (self.options.highlight) {
value = Ox.highlightHTML(value, self.options.highlight, 'OxHighlight'); value = Ox.highlightHTML(value, self.options.highlight, 'OxHighlight', true);
} }
return value; return value;
} }
@ -191,8 +191,8 @@ Ox.Editable = function(options, self) {
self.$input.value().replace(/\n\n+/g, '\0') self.$input.value().replace(/\n\n+/g, '\0')
).replace(/\0/g, '\n\n').trim(); ).replace(/\0/g, '\n\n').trim();
return (self.options.type == 'input' return (self.options.type == 'input'
? Ox.encodeHTML(value) ? Ox.encodeHTMLEntities(value)
: Ox.parseHTML(value) : Ox.sanitizeHTML(value)
); );
} }

View file

@ -834,9 +834,9 @@ Ox.ListMap = function(options, self) {
function decodeValues(place) { function decodeValues(place) {
return Ox.map(place, function(value) { return Ox.map(place, function(value) {
return Ox.isString(value) ? Ox.decodeHTML(value) return Ox.isString(value) ? Ox.decodeHTMLEntities(value)
: Ox.isArray(value) ? Ox.map(value, function(value) { : Ox.isArray(value) ? Ox.map(value, function(value) {
return Ox.decodeHTML(value); return Ox.decodeHTMLEntities(value);
}) })
: value; : value;
}); });
@ -849,9 +849,9 @@ Ox.ListMap = function(options, self) {
function encodeValues(place) { function encodeValues(place) {
return Ox.map(place, function(value) { return Ox.map(place, function(value) {
return Ox.isString(value) ? Ox.encodeHTML(value) return Ox.isString(value) ? Ox.encodeHTMLEntities(value)
: Ox.isArray(value) ? Ox.map(value, function(value) { : Ox.isArray(value) ? Ox.map(value, function(value) {
return Ox.encodeHTML(value); return Ox.encodeHTMLEntities(value);
}) })
: value; : value;
}); });

View file

@ -820,7 +820,7 @@ Ox.VideoEditor = function(options, self) {
if (query.length) { if (query.length) {
query = query.toLowerCase(); query = query.toLowerCase();
results = self.annotations.filter(function(annotation) { results = self.annotations.filter(function(annotation) {
return Ox.decodeHTML(Ox.stripTags( return Ox.decodeHTMLEntities(Ox.stripTags(
annotation.value.toLowerCase() annotation.value.toLowerCase()
)).indexOf(query) > -1; )).indexOf(query) > -1;
}); });
@ -1010,7 +1010,9 @@ Ox.VideoEditor = function(options, self) {
var words = []; var words = [];
Ox.forEach(Ox.count(Ox.words( Ox.forEach(Ox.count(Ox.words(
self.annotations.map(function(annotation) { self.annotations.map(function(annotation) {
return Ox.decodeHTML(Ox.stripTags(annotation.value.toLowerCase())); return Ox.decodeHTMLEntities(
Ox.stripTags(annotation.value.toLowerCase())
);
}).join(' ') }).join(' ')
)), function(count, value) { )), function(count, value) {
words.push({count: count, value: value}); words.push({count: count, value: value});

View file

@ -1173,7 +1173,7 @@ Ox.VideoPlayer = function(options, self) {
if (query.length) { if (query.length) {
query = query.toLowerCase(); query = query.toLowerCase();
results = Ox.filter(self.options.annotations, function(annotation) { results = Ox.filter(self.options.annotations, function(annotation) {
return Ox.decodeHTML(Ox.stripTags( return Ox.decodeHTMLEntities(Ox.stripTags(
annotation.text.toLowerCase() annotation.text.toLowerCase()
)).indexOf(query) > -1; )).indexOf(query) > -1;
}).map(function(annotation) { }).map(function(annotation) {
@ -1184,7 +1184,7 @@ Ox.VideoPlayer = function(options, self) {
}; };
}) })
results = Ox.filter(self.options.annotations, function(annotation) { results = Ox.filter(self.options.annotations, function(annotation) {
return Ox.decodeHTML(Ox.stripTags( return Ox.decodeHTMLEntities(Ox.stripTags(
annotation.text.toLowerCase() annotation.text.toLowerCase()
)).indexOf(query) > -1; )).indexOf(query) > -1;
}).map(function(annotation) { }).map(function(annotation) {

View file

@ -7,7 +7,7 @@ Ox.doc <f> Generates documentation for annotated JavaScript
Present if the <code>type</code> of the item is Present if the <code>type</code> of the item is
<code>"function"</code>. <code>"function"</code>.
description <s|u> Multi-line description with optional markup description <s|u> Multi-line description with optional markup
See Ox.parseHTML for details See Ox.sanitizeHTML for details
events <[o]|u> Events (array of doc objects) events <[o]|u> Events (array of doc objects)
Present if the item fires any events Present if the item fires any events
file <s> File name file <s> File name

View file

@ -75,10 +75,10 @@ Ox.load({Geo: {}, UI: {}, Unicode: {}}, function() {
}) })
.html( .html(
'<span style="font-family: Monaco">' '<span style="font-family: Monaco">'
+ Ox.encodeHTML(test.statement) + ' ' + Ox.encodeHTMLEntities(test.statement) + ' '
+ (test.passed ? '=' : '!') + '=&gt; ' + (test.passed ? '=' : '!') + '=&gt; '
+ Ox.encodeHTML(test.expected) + Ox.encodeHTMLEntities(test.expected)
+ (test.passed ? '' : ' ==&gt; ' + Ox.encodeHTML(test.actual)) + (test.passed ? '' : ' ==&gt; ' + Ox.encodeHTMLEntities(test.actual))
+ '</tt>' + '</tt>'
) )
.appendTo($test.$content); .appendTo($test.$content);