mirror of
https://github.com/reality/dbot.git
synced 2024-12-24 03:33:07 +01:00
Merge pull request #7 from SoftlySplinter/master
Web Module URL encoding.
This commit is contained in:
commit
802279edca
@ -24,13 +24,13 @@ var webInterface = function(dbot) {
|
||||
// Lists the quotes in a category
|
||||
var key = req.params.key.toLowerCase();
|
||||
if(dbot.db.quoteArrs.hasOwnProperty(key)) {
|
||||
res.render('quotes', { 'quotes': dbot.db.quoteArrs[key]});
|
||||
res.render('quotes', { 'quotes': dbot.db.quoteArrs[key], locals: {url_regex: RegExp.prototype.url_regex()}});
|
||||
} else {
|
||||
res.render('error', { 'message': 'No quotes under that key.' });
|
||||
}
|
||||
});
|
||||
|
||||
app.listen(443);
|
||||
app.listen(9443);
|
||||
|
||||
return {
|
||||
'onDestroy': function() {
|
||||
|
41
snippets.js
41
snippets.js
@ -122,3 +122,44 @@ Number.prototype.chanceIn = function(x, y) {
|
||||
var num = Math.floor(Math.random() * (y + 1)) / x;
|
||||
return num == 1;
|
||||
};
|
||||
|
||||
/*** Regex ***/
|
||||
RegExp.prototype.url_regex = function() {
|
||||
var reg = new RegExp(
|
||||
"^" +
|
||||
// protocol identifier
|
||||
"(?:(?:https?|ftp)://)" +
|
||||
// user:pass authentication
|
||||
"(?:\\S+(?::\\S*)?@)?" +
|
||||
"(?:" +
|
||||
// IP address exclusion
|
||||
// private & local networks
|
||||
"(?!10(?:\\.\\d{1,3}){3})" +
|
||||
"(?!127(?:\\.\\d{1,3}){3})" +
|
||||
"(?!169\\.254(?:\\.\\d{1,3}){2})" +
|
||||
"(?!192\\.168(?:\\.\\d{1,3}){2})" +
|
||||
"(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})" +
|
||||
// IP address dotted notation octets
|
||||
// excludes loopback network 0.0.0.0
|
||||
// excludes reserved space >= 224.0.0.0
|
||||
// excludes network & broacast addresses
|
||||
// (first & last IP address of each class)
|
||||
"(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])" +
|
||||
"(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}" +
|
||||
"(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))" +
|
||||
"|" +
|
||||
// host name
|
||||
"(?:(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)" +
|
||||
// domain name
|
||||
"(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)*" +
|
||||
// TLD identifier
|
||||
"(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))" +
|
||||
")" +
|
||||
// port number
|
||||
"(?::\\d{2,5})?" +
|
||||
// resource path
|
||||
"(?:/[^\\s]*)?" +
|
||||
"$", "i"
|
||||
);
|
||||
return reg;
|
||||
}
|
||||
|
@ -1,3 +1,7 @@
|
||||
div#quotelist
|
||||
-each quote in quotes
|
||||
div.quote #{quote}
|
||||
-if(quote.match(locals.url_regex))
|
||||
div.quote
|
||||
a(href=quote)=quote
|
||||
-else
|
||||
div.quote #{quote}
|
||||
|
Loading…
Reference in New Issue
Block a user