Added html escaping GitHub feed. Closes #570

This commit is contained in:
Brandon Mathis 2012-06-11 00:19:05 -05:00
parent bc3553e4f7
commit 3fc0bf107f

View File

@ -38,6 +38,7 @@ var octopress = (function(){
} }
if (sections.length >= 3){ $('aside.sidebar').addClass('thirds'); } if (sections.length >= 3){ $('aside.sidebar').addClass('thirds'); }
} }
, addCodeLineNumbers: function () { , addCodeLineNumbers: function () {
if (navigator.appName === 'Microsoft Internet Explorer') { return; } if (navigator.appName === 'Microsoft Internet Explorer') { return; }
$('div.gist-highlight').each(function(index) { $('div.gist-highlight').each(function(index) {
@ -208,11 +209,21 @@ var octopress = (function(){
})() })()
, github: (function(){ , github: (function(){
htmlEscape = function (str) {
return String(str)
.replace(/&/g, '&')
.replace(/"/g, '"')
.replace(/'/g, ''')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;');
}
function render(target, data){ function render(target, data){
var i = 0, repos = ''; var i = 0, repos = '';
for(i = 0; i < data.length; i++) { for(i = 0; i < data.length; i++) {
repos += '<li><a href="'+data[i].html_url+'">'+data[i].name+'</a><p>'+data[i].description+'</p></li>'; repos += '<li><a href="'+data[i].html_url+'">'+htmlEscape(data[i].name)+'</a><p>'+htmlEscape(data[i].description)+'</p></li>';
} }
target.html(repos); target.html(repos);
} }
@ -264,6 +275,20 @@ $(document).ready(function() {
octopress.github.showRepos('#gh_repos'); octopress.github.showRepos('#gh_repos');
}); });
var htmlEncode = (function() {
var entities = {
'&' : '&amp;'
, '<' : '&lt;'
, '"' : '&quot;'
};
return function(value) {
return value.replace(/[&<"]/g, function(c) {
return entities[c];
});
};
})();
// iOS scaling bug fix // iOS scaling bug fix
// Rewritten version // Rewritten version
// By @mathias, @cheeaun and @jdalton // By @mathias, @cheeaun and @jdalton