parslet
Jordan Orelli 9 years ago
parent 743b650ae6
commit dba23d2cdb

@ -9,6 +9,15 @@ module Bristlecode
tree.to_html
end
def Bristlecode.clean(text)
text.gsub!('&', '&')
text.gsub!('<', '&lt;')
text.gsub!('>', '&gt;')
text.gsub!('"', '&quot;')
text.gsub!("'", '&#x27;')
text.gsub!('/', '&#x2F;')
end
class Parser < Parslet::Parser
rule(:space) { match('\s').repeat(1) }
rule(:space?) { space.maybe }
@ -79,15 +88,7 @@ module Bristlecode
def initialize(text)
self.text = text.to_str.strip
clean
end
def clean
text.gsub!('&', '&amp;')
text.gsub!('<', '&lt;')
text.gsub!('>', '&gt;')
text.gsub!('"', '&quot;')
text.gsub!("'", '&apos;')
Bristlecode.clean(self.text)
end
def to_html

@ -21,8 +21,9 @@ module Bristlecode
expect(to_html('&')).to eq('&amp;')
expect(to_html('>')).to eq('&gt;')
expect(to_html('<')).to eq('&lt;')
expect(to_html("'")).to eq('&apos;')
expect(to_html("'")).to eq('&#x27;')
expect(to_html('"')).to eq('&quot;')
expect(to_html('/')).to eq('&#x2F;')
end
it 'handles plain text just fine' do
@ -66,7 +67,7 @@ module Bristlecode
it 'passes simple url contents opaquely' do
input = '[url]x[b]y[/b]z[/url]'
output = '<a href="x[b]y[/b]z">x[b]y[/b]z</a>'
output = '<a href="x[b]y[/b]z">x[b]y[&#x2F;b]z</a>'
expect(to_html(input)).to eq(output)
end

Loading…
Cancel
Save