diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index d3019afd..18e65999 100755
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -11,13 +11,15 @@ def parse_text(text)
# All this sanitization is probably quite draining. Needs refactoring.
if !text.include?("[code")
- text = h(text)
+ # We would use h here but it escapes quotes, which we need for bbquotes.
+ # This is the code it uses anyway.
+ text = text.gsub(/&/, "&").gsub(/>/, ">").gsub(/, "<")
end
text.gsub!(/(.*?)\[code=?["']?(.*?)["']?\](.*?)\[\/code\](.*?)/mis) { h($1.to_s) + "[code='#{$2}']#{$3}[/code]" + h($4)}
text.gsub!(/\[code=?["']?(.*?)["']?\](.*?)\[\/code\]/mis) { "#{t(:Code)}:
#{clean_code($2)}
"}
- # allows for nested quotes
- bbquote(text)
+ ## Quoting
+ bbquote!(text)
# Parse all similar tags
bbcode("img", "") { text }
@@ -31,7 +33,6 @@ def parse_text(text)
# handle newlines
text.gsub!(/(.*)(\r)+?\n/) { $1 << "
\n" }
-
# handle with care...
bbcode_ext(text)
end
@@ -45,18 +46,16 @@ def clean_code(text)
text.gsub(/^\r\n/, '').gsub(/\r\n$/, '').gsub("<", "<").gsub(">", ">")
end
- # FIXME: this should be named bbquote! with a ! because it blasts the argument out of the water. Or change it to not modify argument
- def bbquote(text)
-# text = text.dup # uncomment this line (please!) if you don't want it to change the argument
+ def bbquote!(text)
if md = text.match( /\[\s*quote=(["'])?([^\1\]]+)(\1)\s*\](?!\[\s*quote=(["'])?([^\1\]]+)(\1)\s*\])(.*?)\[\s*\/\s*quote\s*\]/i )
first, last = md.offset(0)[0], md.offset(0)[1]-1
name, content = md[2], md[7]
text[first..last] = content_tag(:div,
- content_tag(:b,"%s wrote:" % name) +
+ content_tag(:strong,"%s wrote:" % name) +
tag(:br) +
content_tag(:span, content),
:class => 'quote')
- bbquote(text)
+ bbquote!(text)
else
text
end
diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb
index 0c29d508..8d46c1b7 100644
--- a/spec/helpers/application_helper_spec.rb
+++ b/spec/helpers/application_helper_spec.rb
@@ -1,9 +1,5 @@
require File.dirname(__FILE__) + '/../spec_helper'
-class TestView < ActionView::Base
- include ApplicationHelper
-end
-
describe ApplicationHelper, "general" do
include ApplicationHelper
extend ActionView::Helpers::SanitizeHelper::ClassMethods
@@ -20,8 +16,16 @@ class TestView < ActionView::Base
breadcrumb(@sub_of_everybody).should eql("Public Category » Public Forum » Sub of Public Forum")
end
+ it "should accept quotes with single quotes around the name" do
+ parse_text("[quote='Radar']This is a quote[/quote]").should eql("Radar wrote:
This is a quote
")
+ end
+
+ it "should accept quotes with double quotes around the name" do
+ parse_text("[quote=\"Radar\"]This is a quote[/quote]").should eql("Radar wrote:
This is a quote
")
+ end
+
it "should correctly display multiple nested quotes" do
- TestView.new.parse_text('[quote="Kitten"][quote="Dog"][quote="Turtle"]turtle, turtle[/quote]QUOTE INSIDE[/quote]QUOTE OUTSIDE[/quote]').should eql(""Kitten" wrote:"Dog" wrote:"Turtle" wrote:
turtle, turtle
QUOTE INSIDE QUOTE OUTSIDE ")
+ parse_text('[quote="Kitten"][quote="Dog"][quote="Turtle"]turtle, turtle[/quote]QUOTE INSIDE[/quote]QUOTE OUTSIDE[/quote]').should eql("Kitten wrote:Dog wrote:Turtle wrote:
turtle, turtle
QUOTE INSIDE QUOTE OUTSIDE ")
end
it "correctly formats the bbcode when it contains some code blocks" do