Skip to content

Commit

Permalink
mv ecaping to util.safe
Browse files Browse the repository at this point in the history
  • Loading branch information
dodo committed Oct 22, 2011
1 parent f72833a commit afe854a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
9 changes: 8 additions & 1 deletion src/util.coffee
Expand Up @@ -32,5 +32,12 @@ new_attrs = (attrs = {}) ->
strattrs.join ' '


safe = (text) ->
String(text)
.replace(/&(?!\w+;)/g, '&')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')

module.exports = { deep_merge, indent, new_attrs }

module.exports = { deep_merge, indent, new_attrs, safe }
9 changes: 2 additions & 7 deletions src/xml.coffee
@@ -1,5 +1,5 @@
{ EventEmitter } = require 'events'
{ deep_merge, indent, new_attrs } = require './util'
{ deep_merge, indent, new_attrs, safe } = require './util'
EVENTS = ['add', 'attr', 'attr:remove', 'text', 'remove']

new_tag = (name, attrs, children, opts) ->
Expand Down Expand Up @@ -146,12 +146,7 @@ class Tag extends EventEmitter
this

write: (content, {escape} = {}) =>
if escape
content = String(content)
.replace(/&(?!\w+;)/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
content = safe(content) if escape
if @headers
@emit 'data', "#{indent this}#{@headers}>"
delete @headers
Expand Down

0 comments on commit afe854a

Please sign in to comment.