Skip to content

Commit

Permalink
escape HTML output
Browse files Browse the repository at this point in the history
  • Loading branch information
larryng committed May 15, 2012
1 parent 2c853dd commit bde3bc0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
9 changes: 7 additions & 2 deletions coffee/main.coffee
Expand Up @@ -17,6 +17,11 @@ require ['jquery', 'coffee-script', 'nodeutil'], ($, CoffeeScript, nodeutil) ->
$inputr = $('#inputr')
$inputcopy = $('#inputcopy')


escapeHTML = (s) ->
s.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');


class CoffeeREPL
constructor: (@output, @input, @prompt, settings={}) ->
@history = []
Expand Down Expand Up @@ -83,7 +88,7 @@ require ['jquery', 'coffee-script', 'nodeutil'], ($, CoffeeScript, nodeutil) ->
e.preventDefault()
input = @grabInput()

@print @prompt.html() + input
@print @prompt.html() + escapeHTML(input)

if input
@addToSaved input
Expand All @@ -97,7 +102,7 @@ require ['jquery', 'coffee-script', 'nodeutil'], ($, CoffeeScript, nodeutil) ->
if input and @multiline and @saved
input = @grabInput()

@print @prompt.html() + input
@print @prompt.html() + escapeHTML(input)
@addToSaved input
@processSaved()
else if @multiline and @saved
Expand Down
9 changes: 6 additions & 3 deletions js/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion js/nodeutil.js
Expand Up @@ -263,6 +263,9 @@ define(
return reduceToSingleString(output, base, braces);
}

function escapeHTML (s) {
return s.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');
}

function formatPrimitive(ctx, value) {
switch (typeof value) {
Expand All @@ -273,7 +276,7 @@ define(
var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
.replace(/'/g, "\\'")
.replace(/\\"/g, '"') + '\'';
return ctx.stylize(simple, 'string');
return ctx.stylize(escapeHTML(simple), 'string');

case 'number':
return ctx.stylize('' + value, 'number');
Expand Down

0 comments on commit bde3bc0

Please sign in to comment.