Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use better escaping in console/new #210

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion assets/init/scaffolds/page.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
title: {{ title }}
title: {{ title|raw }}
date: {{ date }}
---
2 changes: 1 addition & 1 deletion assets/init/scaffolds/post.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
title: {{ title }}
title: {{ title|raw }}
date: {{ date }}
tags:
---
10 changes: 2 additions & 8 deletions lib/plugins/console/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,13 @@ var moment = require('moment'),
swig = require('swig'),
extend = require('../../extend'),
util = require('../../util'),
escape = util.escape,
file = util.file;

// http://en.wikipedia.org/wiki/Filename#Reserved_characters_and_words
var escape = function(str){
return str.toString().toLowerCase()
.replace(/\s/g, '-')
.replace(/\/|\\|\?|%|\*|:|\||"|<|>|\.|#/g, '');
};

// Default scaffolds
var scaffolds = {
post: [
'title: {{ title }}',
'title: {{ title|raw }}',
'date: {{ date }}',
'tags:',
'---'
Expand Down
16 changes: 2 additions & 14 deletions lib/plugins/processor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,8 @@ var getInfoFromFilename = function(str){
return result;
};

// http://tools.ietf.org/html/rfc3986#section-2.2
// http://en.wikipedia.org/wiki/Filename#Reserved_characters_and_words
var escape = function(str){
var str = str.toString()
.replace(/\s/g, '-')
.replace(/:|\/|\?|#|\[|\]|@|!|\$|&|'|\(|\)|\*|\+|,|;|=|\\|%|<|>|\./g, '');

if (filenameCaps == 1){
str = str.toLowerCase();
} else if (filenameCaps == 2){
str = str.toUpperCase();
}

return str;
var escape = function(str) {
return util.escape(str, filenameCaps);
};

var load = function(file, stat, extname, callback){
Expand Down
17 changes: 17 additions & 0 deletions lib/util/escape.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// http://tools.ietf.org/html/rfc3986#section-2.2
// http://en.wikipedia.org/wiki/Filename#Reserved_characters_and_words
module.exports = function(str, changeCase){
changeCase = changeCase || 0;

var str = str.toString().toLowerCase()
.replace(/\s/g, '-')
.replace(/:|\/|\?|#|\[|\]|@|!|\$|&|'|"|\(|\)|\*|\+|,|;|=|\\|%|<|>|\./g, '');

if (changeCase == 1){
str = str.toLowerCase();
} else if (changeCase == 2){
str = str.toUpperCase();
}

return str;
};
3 changes: 2 additions & 1 deletion lib/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ module.exports = {
exec: require('./exec'),
highlight: require('./highlight'),
titlecase: require('./titlecase'),
Timer: require('./timer')
Timer: require('./timer'),
escape: require('./escape')
};