Skip to content

Commit

Permalink
Sanitize file/folder name before displaying, closed #9
Browse files Browse the repository at this point in the history
  • Loading branch information
buunguyen committed May 14, 2014
1 parent 04cb45e commit a1e8a63
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions src/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,10 @@
, SHOWN = 'octotree.shown'
, REGEXP = /([^\/]+)\/([^\/]+)(?:\/([^\/]+))?/ // (username)/(reponame)/(subpart)
, RESERVED_USER_NAMES = [
'settings',
'organizations',
'site',
'blog',
'about',
'orgs',
'styleguide',
'showcases',
'trending',
'stars',
'dashboard',
'notifications'
'settings', 'orgs', 'organizations',
'site', 'blog', 'about',
'styleguide', 'showcases', 'trending',
'stars', 'dashboard', 'notifications'
]
, RESERVED_REPO_NAMES = ['followers', 'following']

Expand All @@ -37,6 +29,7 @@
'<div class="error"></div>' +
'</form>')
, $toggler = $('<div class="octotree_toggle">&#9776;</div>')
, $dummy = $('<div/>')
, store = new Storage()

$(document).ready(function() {
Expand Down Expand Up @@ -89,21 +82,23 @@
if (err) return done(err)
tree.forEach(function(item) {
var path = item.path
, type = item.type
, index = path.lastIndexOf('/')
, name = path.substring(index + 1)
, folder = folders[path.substring(0, index)]
, url = '/' + repo.username + '/' + repo.reponame + '/' + item.type + '/' + repo.branch + '/' + path
, url = '/' + repo.username + '/' + repo.reponame + '/' + type + '/' + repo.branch + '/' + path

folder.push(item)
item.text = name
item.icon = item.type
if (item.type === 'tree') {
item.text = sanitize(name)
item.icon = type // use `type` as class name for tree node
if (type === 'tree') {
folders[item.path] = item.children = []
item.a_attr = { href: '#' }
}
else if (item.type === 'blob') {
else if (type === 'blob') {
item.a_attr = { href: url }
}
// TOOD: handle submodule
})

done(null, sort(root))
Expand Down Expand Up @@ -211,7 +206,11 @@
}
store.set(TOKEN, token)
loadRepo()
}
}

function sanitize(str) {
return $dummy.text(str).html()
}

function Storage() {
this.get = function(key) {
Expand All @@ -226,4 +225,4 @@
return localStorage.setItem(key, JSON.stringify(val))
}
}
})()
})()

0 comments on commit a1e8a63

Please sign in to comment.