Skip to content

Instantly share code, notes, and snippets.

@headius
Created June 10, 2010 00:26
Show Gist options
  • Save headius/432399 to your computer and use it in GitHub Desktop.
Save headius/432399 to your computer and use it in GitHub Desktop.
class DubyApp < HttpServlet
def_edb(list, 'com/ribrdb/list.dhtml')
def doGet(request, response)
@posts = Post.all.run
response.getWriter.write(list)
end
def doPost(request, response)
post = Post.new
post.title = request.getParameter('title')
post.body = request.getParameter('body')
post.save
doGet(request, response)
end
def initialize
@escape_pattern = Pattern.compile("[<>&'\"]")
@escaped = HashMap.new
@escaped.put("<", "&lt;")
@escaped.put(">", "&gt;")
@escaped.put("&", "&amp;")
@escaped.put("\"", "&quot;")
@escaped.put("'", "&#39;")
end
def h(text:String)
return "" unless text
matcher = @escape_pattern.matcher(text)
buffer = StringBuffer.new
while matcher.find
replacement = String(@escaped.get(matcher.group))
matcher.appendReplacement(buffer, replacement)
end
matcher.appendTail(buffer)
return buffer.toString
end
def h(o:Object)
return "" unless o
h(o.toString)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment