Permalink
Browse files

HTML special chars are now escaped correctly

  • Loading branch information...
1 parent 882a37a commit 56f3d7278d4ad57773eb4d75066c38d1d01325e0 @fgnass committed Mar 11, 2011
Showing with 15 additions and 5 deletions.
  1. +15 −5 Support/jshint-tm.js
View
@@ -1,27 +1,37 @@
var sys = require("sys"),
fs = require("fs"),
env = process.env || process.ENV,
- JSHINT = require('./jshint.js').JSHINT;
+ JSHINT = require('./jshint.js').JSHINT,
+ entities = {
+ '&': '&',
+ '"': '"',
+ '<': '&lt;',
+ '>': '&gt;'
+ };
+
+function html(s) {
+ return (s || '').replace(/[&"<>]/g, function(c) {return entities[c] || c;});
+}
module.exports = function (options) {
var file = env.TM_FILEPATH,
input = fs.readFileSync(file, 'utf8'),
body = '';
//remove shebang
- input = input.replace(/^\#\!.*/, "");
+ input = input.replace(/^\#\!.*/, '');
if (!JSHINT(input, options)) {
JSHINT.errors.forEach(function(e) {
if (e) {
body += ('<a href="txmt://open?url=file://' + escape(file) + '&line=' + e.line + '&column=' + e.character + '">' + e.reason);
if (e.evidence && !isNaN(e.character)) {
body += '<tt>';
- body += e.evidence.substring(0, e.character-1);
+ body += html(e.evidence.substring(0, e.character-1));
body += '<em>';
- body += (e.character <= e.evidence.length) ? e.evidence.substring(e.character-1, e.character) : '&nbsp;';
+ body += (e.character <= e.evidence.length) ? html(e.evidence.substring(e.character-1, e.character)) : '&nbsp;';
body += '</em>';
- body += e.evidence.substring(e.character);
+ body += html(e.evidence.substring(e.character));
body += '</tt>';
}
body += '</a>';

0 comments on commit 56f3d72

Please sign in to comment.