Fix RuboCop offense Layout/SpaceInsideParens, one of the offenses enabled in rubocop-rails-omakase (#39887).

git-svn-id: https://svn.redmine.org/redmine/trunk@22954 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Go MAEDA
2024-08-12 08:45:54 +00:00
parent 6e21ae7209
commit b3d1deeece
10 changed files with 153 additions and 168 deletions

View File

@@ -144,21 +144,6 @@ Layout/SpaceInsideArrayLiteralBrackets:
- 'lib/redmine/string_array_diff/diff.rb' - 'lib/redmine/string_array_diff/diff.rb'
- 'test/unit/mailer_localisation_test.rb' - 'test/unit/mailer_localisation_test.rb'
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: space, compact, no_space
Layout/SpaceInsideParens:
Exclude:
- 'app/helpers/issues_helper.rb'
- 'app/models/auth_source_ldap.rb'
- 'app/models/repository/cvs.rb'
- 'lib/redmine/sudo_mode.rb'
- 'lib/redmine/wiki_formatting/textile/formatter.rb'
- 'lib/redmine/wiki_formatting/textile/redcloth3.rb'
- 'test/unit/changeset_test.rb'
- 'test/unit/issue_subtasking_test.rb'
- 'test/unit/lib/redmine/export/pdf_test.rb'
# This cop supports safe autocorrection (--autocorrect). # This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle. # Configuration parameters: EnforcedStyle.
# SupportedStyles: space, no_space # SupportedStyles: space, no_space

View File

@@ -392,7 +392,7 @@ module IssuesHelper
content = content =
content_tag('hr') + content_tag('hr') +
content_tag('p', content_tag('strong', custom_field_name_tag(value.custom_field) )) + content_tag('p', content_tag('strong', custom_field_name_tag(value.custom_field))) +
content_tag('div', attr_value_tag, class: 'value') content_tag('div', attr_value_tag, class: 'value')
s << content_tag('div', content, class: "#{value.custom_field.css_classes} attribute") s << content_tag('div', content, class: "#{value.custom_field.css_classes} attribute")
end end

View File

@@ -229,7 +229,7 @@ class AuthSourceLdap < AuthSource
end end
attrs = {} attrs = {}
search_filter = base_filter & Net::LDAP::Filter.eq(self.attr_login, login) search_filter = base_filter & Net::LDAP::Filter.eq(self.attr_login, login)
ldap_con.search( :base => self.base_dn, ldap_con.search(:base => self.base_dn,
:filter => search_filter, :filter => search_filter,
:attributes=> search_attributes) do |entry| :attributes=> search_attributes) do |entry|
if onthefly_register? if onthefly_register?

View File

@@ -59,7 +59,7 @@ class Repository::Cvs < Repository
entries = scm.entries(path, rev.nil? ? nil : rev.committed_on) entries = scm.entries(path, rev.nil? ? nil : rev.committed_on)
if entries if entries
entries.each do |entry| entries.each do |entry|
if ( ! entry.lastrev.nil? ) && ( ! entry.lastrev.revision.nil? ) if (! entry.lastrev.nil?) && (! entry.lastrev.revision.nil?)
change = change =
filechanges.where( filechanges.where(
:revision => entry.lastrev.revision, :revision => entry.lastrev.revision,

View File

@@ -121,7 +121,7 @@ module Redmine
# display the sudo password form # display the sudo password form
def render_sudo_form(param_names) def render_sudo_form(param_names)
@sudo_form ||= SudoMode::Form.new @sudo_form ||= SudoMode::Form.new
@sudo_form.original_fields = params.slice( *param_names ) @sudo_form.original_fields = params.slice(*param_names)
# a simple 'render "sudo_mode/new"' works when used directly inside an # a simple 'render "sudo_mode/new"' works when used directly inside an
# action, but not when called from a before_action: # action, but not when called from a before_action:
respond_to do |format| respond_to do |format|
@@ -157,7 +157,7 @@ module Redmine
if controller.api_request? if controller.api_request?
true true
elsif SudoMode.possible? && method_matches elsif SudoMode.possible? && method_matches
controller.require_sudo_mode( *parameters ) controller.require_sudo_mode(*parameters)
else else
true true
end end

View File

@@ -95,13 +95,13 @@ module Redmine
# Patch for RedCloth. Fixed in RedCloth r128 but _why hasn't released it yet. # Patch for RedCloth. Fixed in RedCloth r128 but _why hasn't released it yet.
# <a href="http://code.whytheluckystiff.net/redcloth/changeset/128">http://code.whytheluckystiff.net/redcloth/changeset/128</a> # <a href="http://code.whytheluckystiff.net/redcloth/changeset/128">http://code.whytheluckystiff.net/redcloth/changeset/128</a>
def hard_break( text ) def hard_break(text)
text.gsub!( /(.)\n(?!\n|\Z| *([#*=]+(\s|$)|[{|]))/, "\\1<br />" ) if hard_breaks text.gsub!(/(.)\n(?!\n|\Z| *([#*=]+(\s|$)|[{|]))/, "\\1<br />") if hard_breaks
end end
alias :smooth_offtags_without_code_highlighting :smooth_offtags alias :smooth_offtags_without_code_highlighting :smooth_offtags
# Patch to add code highlighting support to RedCloth # Patch to add code highlighting support to RedCloth
def smooth_offtags( text ) def smooth_offtags(text)
unless @pre_list.empty? unless @pre_list.empty?
## replace <pre> content ## replace <pre> content
text.gsub!(/<redpre#(\d+)>/) do text.gsub!(/<redpre#(\d+)>/) do

View File

@@ -254,9 +254,9 @@ class RedCloth3 < String
# r.to_html # r.to_html
# #=>"<h1>A &lt;b&gt;bold&lt;/b&gt; man</h1>" # #=>"<h1>A &lt;b&gt;bold&lt;/b&gt; man</h1>"
# #
def initialize( string, restrictions = [] ) def initialize(string, restrictions = [])
restrictions.each { |r| method( :"#{r}=" ).call( true ) } restrictions.each { |r| method(:"#{r}=").call(true) }
super( string ) super(string)
end end
# #
@@ -266,7 +266,7 @@ class RedCloth3 < String
# r.to_html( true ) # r.to_html( true )
# #=>"And then? She <strong>fell</strong>!" # #=>"And then? She <strong>fell</strong>!"
# #
def to_html( *rules ) def to_html(*rules)
rules = DEFAULT_RULES if rules.empty? rules = DEFAULT_RULES if rules.empty?
# make our working copy # make our working copy
text = self.dup text = self.dup
@@ -312,8 +312,8 @@ class RedCloth3 < String
retrieve text retrieve text
text.gsub!( /<\/?notextile>/, '' ) text.gsub!(/<\/?notextile>/, '')
text.gsub!( "x%x%", '&#38;' ) text.gsub!("x%x%", '&#38;')
clean_html text if filter_html clean_html text if filter_html
text.strip! text.strip!
text text
@@ -332,7 +332,7 @@ class RedCloth3 < String
[147, 8220], [148, 8221], [149, 8226], [150, 8211], [151, 8212], [152, 732], [147, 8220], [148, 8221], [149, 8226], [150, 8211], [151, 8212], [152, 732],
[153, 8482], [154, 353], [155, 8250], [156, 339], [157, 0], [158, 0], [159, 376]]. [153, 8482], [154, 353], [155, 8250], [156, 339], [157, 0], [158, 0], [159, 376]].
collect! do |a, b| collect! do |a, b|
[a.chr, ( b.zero? and "" or "&#{b};" )] [a.chr, (b.zero? and "" or "&#{b};")]
end end
# #
# Regular expressions to convert to HTML. # Regular expressions to convert to HTML.
@@ -348,9 +348,9 @@ class RedCloth3 < String
S = "(?:#{S_CSPN}?#{S_RSPN}|#{S_RSPN}?#{S_CSPN}?)" S = "(?:#{S_CSPN}?#{S_RSPN}|#{S_RSPN}?#{S_CSPN}?)"
C = "(?:#{C_CLAS}?#{C_STYL}?#{C_LNGE}?|#{C_STYL}?#{C_LNGE}?#{C_CLAS}?|#{C_LNGE}?#{C_STYL}?#{C_CLAS}?)" C = "(?:#{C_CLAS}?#{C_STYL}?#{C_LNGE}?|#{C_STYL}?#{C_LNGE}?#{C_CLAS}?|#{C_LNGE}?#{C_STYL}?#{C_CLAS}?)"
# PUNCT = Regexp::quote( '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~' ) # PUNCT = Regexp::quote( '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~' )
PUNCT = Regexp::quote( '!"#$%&\'*+,-./:;=?@\\^_`|~' ) PUNCT = Regexp::quote('!"#$%&\'*+,-./:;=?@\\^_`|~')
PUNCT_NOQ = Regexp::quote( '!"#$&\',./:;=?@\\`|' ) PUNCT_NOQ = Regexp::quote('!"#$&\',./:;=?@\\`|')
PUNCT_Q = Regexp::quote( '*-_+^~%' ) PUNCT_Q = Regexp::quote('*-_+^~%')
HYPERLINK = '(\S+?)([^\w\s/;=\?]*?)(?=\s|<|$)' HYPERLINK = '(\S+?)([^\w\s/;=\?]*?)(?=\s|<|$)'
# Text markup tags, don't conflict with block tags # Text markup tags, don't conflict with block tags
@@ -438,19 +438,19 @@ class RedCloth3 < String
# #
# Flexible HTML escaping # Flexible HTML escaping
# #
def htmlesc( str, mode=:Quotes ) def htmlesc(str, mode=:Quotes)
if str if str
str.gsub!( '&', '&amp;' ) str.gsub!('&', '&amp;')
str.gsub!( '"', '&quot;' ) if mode != :NoQuotes str.gsub!('"', '&quot;') if mode != :NoQuotes
str.gsub!( "'", '&#039;' ) if mode == :Quotes str.gsub!("'", '&#039;') if mode == :Quotes
str.gsub!( '<', '&lt;') str.gsub!('<', '&lt;')
str.gsub!( '>', '&gt;') str.gsub!('>', '&gt;')
end end
str str
end end
# Search and replace for Textile glyphs (quotes, dashes, other symbols) # Search and replace for Textile glyphs (quotes, dashes, other symbols)
def pgl( text ) def pgl(text)
# GLYPHS.each do |re, resub, tog| # GLYPHS.each do |re, resub, tog|
# next if tog and method( tog ).call # next if tog and method( tog ).call
# text.gsub! re, resub # text.gsub! re, resub
@@ -461,7 +461,7 @@ class RedCloth3 < String
end end
# Parses Textile attribute lists and builds an HTML attribute string # Parses Textile attribute lists and builds an HTML attribute string
def pba( text_in, element = "" ) def pba(text_in, element = "")
return +'' unless text_in return +'' unless text_in
style = [] style = []
@@ -472,21 +472,21 @@ class RedCloth3 < String
style << "vertical-align:#{v_align($&)};" if text =~ A_VLGN style << "vertical-align:#{v_align($&)};" if text =~ A_VLGN
end end
if text.sub!( /\{([^"}]*)\}/, '' ) && !filter_styles if text.sub!(/\{([^"}]*)\}/, '') && !filter_styles
sanitized = sanitize_styles($1) sanitized = sanitize_styles($1)
style << "#{sanitized};" unless sanitized.blank? style << "#{sanitized};" unless sanitized.blank?
end end
lang = $1 if lang = $1 if
text.sub!( /\[([a-z\-_]+?)\]/, '' ) text.sub!(/\[([a-z\-_]+?)\]/, '')
cls = $1 if cls = $1 if
text.sub!( /\(([^()]+?)\)/, '' ) text.sub!(/\(([^()]+?)\)/, '')
style << "padding-left:#{$1.length}em;" if style << "padding-left:#{$1.length}em;" if
text.sub!( /([(]+)/, '' ) text.sub!(/([(]+)/, '')
style << "padding-right:#{$1.length}em;" if text.sub!( /([)]+)/, '' ) style << "padding-right:#{$1.length}em;" if text.sub!(/([)]+)/, '')
style << "text-align:#{h_align($&)};" if text =~ A_HLGN style << "text-align:#{h_align($&)};" if text =~ A_HLGN
@@ -524,15 +524,15 @@ class RedCloth3 < String
TABLE_RE = /^(?:table(_?#{S}#{A}#{C})\. ?\n)?^(#{A}#{C}\.? ?\|.*?\|)(\n\n|\Z)/m TABLE_RE = /^(?:table(_?#{S}#{A}#{C})\. ?\n)?^(#{A}#{C}\.? ?\|.*?\|)(\n\n|\Z)/m
# Parses a Textile table block, building HTML from the result. # Parses a Textile table block, building HTML from the result.
def block_textile_table( text ) def block_textile_table(text)
text.gsub!( TABLE_RE ) do |matches| text.gsub!(TABLE_RE) do |matches|
tatts, fullrow = $~[1..2] tatts, fullrow = $~[1..2]
tatts = pba( tatts, 'table' ) tatts = pba(tatts, 'table')
tatts = shelve( tatts ) if tatts tatts = shelve(tatts) if tatts
rows = [] rows = []
fullrow.gsub!(/([^|\s])\s*\n/, "\\1<br />") fullrow.gsub!(/([^|\s])\s*\n/, "\\1<br />")
fullrow.each_line do |row| fullrow.each_line do |row|
ratts, row = pba( $1, 'tr' ), $2 if row =~ /^(#{A}#{C}\. )(.*)/mo ratts, row = pba($1, 'tr'), $2 if row =~ /^(#{A}#{C}\. )(.*)/mo
cells = [] cells = []
# the regexp prevents wiki links with a | from being cut as cells # the regexp prevents wiki links with a | from being cut as cells
row.scan(/\|(_?#{S}#{A}#{C}\. ?)?((\[\[[^|\]]*\|[^|\]]*\]\]|[^|])*?)(?=\|)/o) do |modifiers, cell| row.scan(/\|(_?#{S}#{A}#{C}\. ?)?((\[\[[^|\]]*\|[^|\]]*\]\]|[^|])*?)(?=\|)/o) do |modifiers, cell|
@@ -540,12 +540,12 @@ class RedCloth3 < String
ctyp = 'h' if modifiers&.start_with?('_') ctyp = 'h' if modifiers&.start_with?('_')
catts = nil catts = nil
catts = pba( modifiers, 'td' ) if modifiers catts = pba(modifiers, 'td') if modifiers
catts = shelve( catts ) if catts catts = shelve(catts) if catts
cells << "\t\t\t<t#{ctyp}#{catts}>#{cell}</t#{ctyp}>" cells << "\t\t\t<t#{ctyp}#{catts}>#{cell}</t#{ctyp}>"
end end
ratts = shelve( ratts ) if ratts ratts = shelve(ratts) if ratts
rows << "\t\t<tr#{ratts}>\n#{cells.join("\n")}\n\t\t</tr>" rows << "\t\t<tr#{ratts}>\n#{cells.join("\n")}\n\t\t</tr>"
end end
"\t<table#{tatts}>\n#{rows.join("\n")}\n\t</table>\n\n" "\t<table#{tatts}>\n#{rows.join("\n")}\n\t</table>\n\n"
@@ -556,9 +556,9 @@ class RedCloth3 < String
LISTS_CONTENT_RE = /^([#*]+)(#{A}#{C}) (.*)$/m LISTS_CONTENT_RE = /^([#*]+)(#{A}#{C}) (.*)$/m
# Parses Textile lists and generates HTML # Parses Textile lists and generates HTML
def block_textile_lists( text ) def block_textile_lists(text)
text.gsub!( LISTS_RE ) do |match| text.gsub!(LISTS_RE) do |match|
lines = match.split( "\n" ) lines = match.split("\n")
last_line = -1 last_line = -1
depth = [] depth = []
lines.each_with_index do |line, line_id| lines.each_with_index do |line, line_id|
@@ -578,8 +578,8 @@ class RedCloth3 < String
end end
if depth.last != tl if depth.last != tl
depth << tl depth << tl
atts = pba( atts ) atts = pba(atts)
atts = shelve( atts ) if atts atts = shelve(atts) if atts
lines[line_id] = +"\t<#{lT(tl)}l#{atts}>\n\t<li>#{content}" lines[line_id] = +"\t<#{lT(tl)}l#{atts}>\n\t<li>#{content}"
else else
lines[line_id] = +"\t\t<li>#{content}" lines[line_id] = +"\t\t<li>#{content}"
@@ -594,16 +594,16 @@ class RedCloth3 < String
end end
end end
end end
lines.join( "\n" ) lines.join("\n")
end end
end end
QUOTES_RE = /(^>+([^\n]*?)(\n|$))+/m QUOTES_RE = /(^>+([^\n]*?)(\n|$))+/m
QUOTES_CONTENT_RE = /^([> ]+)(.*)$/m QUOTES_CONTENT_RE = /^([> ]+)(.*)$/m
def block_textile_quotes( text ) def block_textile_quotes(text)
text.gsub!( QUOTES_RE ) do |match| text.gsub!(QUOTES_RE) do |match|
lines = match.split( "\n" ) lines = match.split("\n")
quotes = +'' quotes = +''
indent = 0 indent = 0
lines.each do |line| lines.each do |line|
@@ -628,26 +628,26 @@ class RedCloth3 < String
@ @
(?=\W)/x (?=\W)/x
def inline_textile_code( text ) def inline_textile_code(text)
text.gsub!( CODE_RE ) do |m| text.gsub!(CODE_RE) do |m|
before, lang, code, after = $~[1..4] before, lang, code, after = $~[1..4]
lang = " lang=\"#{lang}\"" if lang lang = " lang=\"#{lang}\"" if lang
rip_offtags( +"#{before}<code#{lang}>#{code}</code>#{after}", false ) rip_offtags(+"#{before}<code#{lang}>#{code}</code>#{after}", false)
end end
end end
def lT( text ) def lT(text)
text.end_with?('#') ? 'o' : 'u' text.end_with?('#') ? 'o' : 'u'
end end
def hard_break( text ) def hard_break(text)
text.gsub!( /(.)\n(?!\Z| *([#*=]+(\s|$)|[{|]))/, "\\1<br />" ) if hard_breaks text.gsub!(/(.)\n(?!\Z| *([#*=]+(\s|$)|[{|]))/, "\\1<br />") if hard_breaks
end end
BLOCKS_GROUP_RE = /\n{2,}(?! )/m BLOCKS_GROUP_RE = /\n{2,}(?! )/m
def blocks( text, deep_code = false ) def blocks(text, deep_code = false)
text.replace( text.split( BLOCKS_GROUP_RE ).collect do |blk| text.replace(text.split(BLOCKS_GROUP_RE).collect do |blk|
plain = blk !~ /\A[#*> ]/ plain = blk !~ /\A[#*> ]/
# skip blocks that are complex HTML # skip blocks that are complex HTML
@@ -660,10 +660,10 @@ class RedCloth3 < String
blk blk
else else
code_blk = nil code_blk = nil
blk.gsub!( /((?:\n(?:\n^ +[^\n]*)+)+)/m ) do |iblk| blk.gsub!(/((?:\n(?:\n^ +[^\n]*)+)+)/m) do |iblk|
flush_left iblk flush_left iblk
blocks iblk, plain blocks iblk, plain
iblk.gsub( /^(\S)/, "\t\\1" ) iblk.gsub(/^(\S)/, "\t\\1")
if plain if plain
code_blk = iblk; "" code_blk = iblk; ""
else else
@@ -686,18 +686,18 @@ class RedCloth3 < String
blk + "\n#{code_blk}" blk + "\n#{code_blk}"
end end
end end
end.join( "\n\n" ) ) end.join("\n\n"))
end end
def textile_bq( tag, atts, cite, content ) def textile_bq(tag, atts, cite, content)
cite, cite_title = check_refs( cite ) cite, cite_title = check_refs(cite)
cite = " cite=\"#{htmlesc cite.dup}\"" if cite cite = " cite=\"#{htmlesc cite.dup}\"" if cite
atts = shelve( atts ) if atts atts = shelve(atts) if atts
"\t<blockquote#{cite}>\n\t\t<p#{atts}>#{content}</p>\n\t</blockquote>" "\t<blockquote#{cite}>\n\t\t<p#{atts}>#{content}</p>\n\t</blockquote>"
end end
def textile_p( tag, atts, cite, content ) def textile_p(tag, atts, cite, content)
atts = shelve( atts ) if atts atts = shelve(atts) if atts
"\t<#{tag}#{atts}>#{content}</#{tag}>" "\t<#{tag}#{atts}>#{content}</#{tag}>"
end end
@@ -708,38 +708,38 @@ class RedCloth3 < String
alias textile_h5 textile_p alias textile_h5 textile_p
alias textile_h6 textile_p alias textile_h6 textile_p
def textile_fn_( tag, num, atts, cite, content ) def textile_fn_(tag, num, atts, cite, content)
atts << " id=\"fn#{num}\" class=\"footnote\"" atts << " id=\"fn#{num}\" class=\"footnote\""
content = "<sup>#{num}</sup> #{content}" content = "<sup>#{num}</sup> #{content}"
atts = shelve( atts ) if atts atts = shelve(atts) if atts
"\t<p#{atts}>#{content}</p>" "\t<p#{atts}>#{content}</p>"
end end
BLOCK_RE = /^(([a-z]+)(\d*))(#{A}#{C})\.(?::(\S+))? (.*)$/m BLOCK_RE = /^(([a-z]+)(\d*))(#{A}#{C})\.(?::(\S+))? (.*)$/m
def block_textile_prefix( text ) def block_textile_prefix(text)
if text =~ BLOCK_RE if text =~ BLOCK_RE
tag, tagpre, num, atts, cite, content = $~[1..6] tag, tagpre, num, atts, cite, content = $~[1..6]
atts = pba( atts ) atts = pba(atts)
# pass to prefix handler # pass to prefix handler
replacement = nil replacement = nil
if respond_to? :"textile_#{tag}", true if respond_to? :"textile_#{tag}", true
replacement = method( :"textile_#{tag}" ).call( tag, atts, cite, content ) replacement = method(:"textile_#{tag}").call(tag, atts, cite, content)
elsif respond_to? :"textile_#{tagpre}_", true elsif respond_to? :"textile_#{tagpre}_", true
replacement = method( :"textile_#{tagpre}_" ).call( tagpre, num, atts, cite, content ) replacement = method(:"textile_#{tagpre}_").call(tagpre, num, atts, cite, content)
end end
text.gsub!( $& ) { replacement } if replacement text.gsub!($&) { replacement } if replacement
end end
end end
SETEXT_RE = /\A(.+?)\n([=-])[=-]* *$/m SETEXT_RE = /\A(.+?)\n([=-])[=-]* *$/m
def block_markdown_setext( text ) def block_markdown_setext(text)
if text =~ SETEXT_RE if text =~ SETEXT_RE
tag = ($2 == "=" ? "h1" : "h2") tag = ($2 == "=" ? "h1" : "h2")
blk, cont = "<#{tag}>#{$1}</#{tag}>", $' blk, cont = "<#{tag}>#{$1}</#{tag}>", $'
blocks cont blocks cont
text.replace( blk + cont ) text.replace(blk + cont)
end end
end end
@@ -749,44 +749,44 @@ class RedCloth3 < String
[ ]* [ ]*
\#* # optional closing #'s (not counted) \#* # optional closing #'s (not counted)
$/x $/x
def block_markdown_atx( text ) def block_markdown_atx(text)
if text =~ ATX_RE if text =~ ATX_RE
tag = "h#{$1.length}" tag = "h#{$1.length}"
blk, cont = "<#{tag}>#{$2}</#{tag}>\n\n", $' blk, cont = "<#{tag}>#{$2}</#{tag}>\n\n", $'
blocks cont blocks cont
text.replace( blk + cont ) text.replace(blk + cont)
end end
end end
MARKDOWN_BQ_RE = /\A(^ *> ?.+$(.+\n)*\n*)+/m MARKDOWN_BQ_RE = /\A(^ *> ?.+$(.+\n)*\n*)+/m
def block_markdown_bq( text ) def block_markdown_bq(text)
text.gsub!( MARKDOWN_BQ_RE ) do |blk| text.gsub!(MARKDOWN_BQ_RE) do |blk|
blk.gsub!( /^ *> ?/, '' ) blk.gsub!(/^ *> ?/, '')
flush_left blk flush_left blk
blocks blk blocks blk
blk.gsub!( /^(\S)/, "\t\\1" ) blk.gsub!(/^(\S)/, "\t\\1")
"<blockquote>\n#{blk}\n</blockquote>\n\n" "<blockquote>\n#{blk}\n</blockquote>\n\n"
end end
end end
MARKDOWN_RULE_RE = /^(#{ MARKDOWN_RULE_RE = /^(#{
['*', '-', '_'].collect { |ch| ' ?(' + Regexp::quote( ch ) + ' ?){3,}' }.join( '|' ) ['*', '-', '_'].collect { |ch| ' ?(' + Regexp::quote(ch) + ' ?){3,}' }.join('|')
})$/ })$/
def block_markdown_rule( text ) def block_markdown_rule(text)
text.gsub!( MARKDOWN_RULE_RE ) do |blk| text.gsub!(MARKDOWN_RULE_RE) do |blk|
"<hr />" "<hr />"
end end
end end
# XXX TODO XXX # XXX TODO XXX
def block_markdown_lists( text ) def block_markdown_lists(text)
end end
def inline_textile_span( text ) def inline_textile_span(text)
QTAGS.each do |qtag_rc, ht, qtag_re, rtype| QTAGS.each do |qtag_rc, ht, qtag_re, rtype|
text.gsub!( qtag_re ) do |m| text.gsub!(qtag_re) do |m|
case rtype case rtype
when :limit when :limit
sta, oqs, qtag, content, oqa = $~[1..6] sta, oqs, qtag, content, oqa = $~[1..6]
@@ -798,8 +798,8 @@ class RedCloth3 < String
qtag, atts, cite, content = $~[1..4] qtag, atts, cite, content = $~[1..4]
sta = '' sta = ''
end end
atts = pba( atts ) atts = pba(atts)
atts = shelve( atts ) if atts atts = shelve(atts) if atts
"#{sta}#{oqs}<#{ht}#{atts}>#{content}</#{ht}>#{oqa}" "#{sta}#{oqs}<#{ht}#{atts}>#{content}</#{ht}>#{oqa}"
end end
@@ -825,8 +825,8 @@ class RedCloth3 < String
(?=<|\s|$) (?=<|\s|$)
/x /x
def inline_textile_link( text ) def inline_textile_link(text)
text.gsub!( LINK_RE ) do |m| text.gsub!(LINK_RE) do |m|
all, pre, atts, text, title, url, proto, slash, post = $~[1..9] all, pre, atts, text, title, url, proto, slash, post = $~[1..9]
if text.include?('<br />') if text.include?('<br />')
all all
@@ -860,19 +860,19 @@ class RedCloth3 < String
\[(.*?)\] # $id \[(.*?)\] # $id
/x /x
def inline_markdown_reflink( text ) def inline_markdown_reflink(text)
text.gsub!( MARKDOWN_REFLINK_RE ) do |m| text.gsub!(MARKDOWN_REFLINK_RE) do |m|
text, id = $~[1..2] text, id = $~[1..2]
if id.empty? if id.empty?
url, title = check_refs( text ) url, title = check_refs(text)
else else
url, title = check_refs( id ) url, title = check_refs(id)
end end
atts = " href=\"#{url}\"" atts = " href=\"#{url}\""
atts << " title=\"#{title}\"" if title atts << " title=\"#{title}\"" if title
atts = shelve( atts ) atts = shelve(atts)
"<a#{atts}>#{text}</a>" "<a#{atts}>#{text}</a>"
end end
@@ -892,13 +892,13 @@ class RedCloth3 < String
\) \)
/x /x
def inline_markdown_link( text ) def inline_markdown_link(text)
text.gsub!( MARKDOWN_LINK_RE ) do |m| text.gsub!(MARKDOWN_LINK_RE) do |m|
text, url, quote, title = $~[1..4] text, url, quote, title = $~[1..4]
atts = " href=\"#{url}\"" atts = " href=\"#{url}\""
atts << " title=\"#{title}\"" if title atts << " title=\"#{title}\"" if title
atts = shelve( atts ) atts = shelve(atts)
"<a#{atts}>#{text}</a>" "<a#{atts}>#{text}</a>"
end end
@@ -907,22 +907,22 @@ class RedCloth3 < String
TEXTILE_REFS_RE = /(^ *)\[([^\[\n]+?)\](#{HYPERLINK})(?=\s|$)/ TEXTILE_REFS_RE = /(^ *)\[([^\[\n]+?)\](#{HYPERLINK})(?=\s|$)/
MARKDOWN_REFS_RE = /(^ *)\[([^\n]+?)\]:\s+<?(#{HYPERLINK})>?(?:\s+"((?:[^"]|\\")+)")?(?=\s|$)/m MARKDOWN_REFS_RE = /(^ *)\[([^\n]+?)\]:\s+<?(#{HYPERLINK})>?(?:\s+"((?:[^"]|\\")+)")?(?=\s|$)/m
def refs( text ) def refs(text)
@rules.each do |rule_name| @rules.each do |rule_name|
method( rule_name ).call( text ) if rule_name.to_s.start_with?('refs_') method(rule_name).call(text) if rule_name.to_s.start_with?('refs_')
end end
end end
def refs_textile( text ) def refs_textile(text)
text.gsub!( TEXTILE_REFS_RE ) do |m| text.gsub!(TEXTILE_REFS_RE) do |m|
flag, url = $~[2..3] flag, url = $~[2..3]
@urlrefs[flag.downcase] = [url, nil] @urlrefs[flag.downcase] = [url, nil]
nil nil
end end
end end
def refs_markdown( text ) def refs_markdown(text)
text.gsub!( MARKDOWN_REFS_RE ) do |m| text.gsub!(MARKDOWN_REFS_RE) do |m|
flag, url = $~[2..3] flag, url = $~[2..3]
title = $~[6] title = $~[6]
@urlrefs[flag.downcase] = [url, title] @urlrefs[flag.downcase] = [url, title]
@@ -930,7 +930,7 @@ class RedCloth3 < String
end end
end end
def check_refs( text ) def check_refs(text)
ret = @urlrefs[text.downcase] if text ret = @urlrefs[text.downcase] if text
ret || [text, nil] ret || [text, nil]
end end
@@ -948,19 +948,19 @@ class RedCloth3 < String
(?::#{HYPERLINK})? # optional href (?::#{HYPERLINK})? # optional href
/x /x
def inline_textile_image( text ) def inline_textile_image(text)
text.gsub!( IMAGE_RE ) do |m| text.gsub!(IMAGE_RE) do |m|
stln, algn, atts, url, title, href, href_a1, href_a2 = $~[1..8] stln, algn, atts, url, title, href, href_a1, href_a2 = $~[1..8]
htmlesc title htmlesc title
atts = pba( atts ) atts = pba(atts)
atts = +" src=\"#{htmlesc url.dup}\"#{atts}" atts = +" src=\"#{htmlesc url.dup}\"#{atts}"
atts << " title=\"#{title}\"" if title atts << " title=\"#{title}\"" if title
atts << " alt=\"#{title}\"" atts << " alt=\"#{title}\""
# size = @getimagesize($url); # size = @getimagesize($url);
# if($size) $atts.= " $size[3]"; # if($size) $atts.= " $size[3]";
href, alt_title = check_refs( href ) if href href, alt_title = check_refs(href) if href
url, url_title = check_refs( url ) url, url_title = check_refs(url)
next m unless uri_with_safe_scheme?(url.partition('?').first) next m unless uri_with_safe_scheme?(url.partition('?').first)
if href if href
@@ -974,7 +974,7 @@ class RedCloth3 < String
out << "</a>#{href_a1}#{href_a2}" if href out << "</a>#{href_a1}#{href_a2}" if href
if algn if algn
algn = h_align( algn ) algn = h_align(algn)
if stln == "<p>" if stln == "<p>"
out = "<p style=\"float:#{algn}\">#{out}" out = "<p style=\"float:#{algn}\">#{out}"
else else
@@ -988,47 +988,47 @@ class RedCloth3 < String
end end
end end
def shelve( val ) def shelve(val)
@shelf << val @shelf << val
" :redsh##{@shelf.length}:" " :redsh##{@shelf.length}:"
end end
def retrieve( text ) def retrieve(text)
text.gsub!(/ :redsh#(\d+):/) do text.gsub!(/ :redsh#(\d+):/) do
@shelf[$1.to_i - 1] || $& @shelf[$1.to_i - 1] || $&
end end
end end
def incoming_entities( text ) def incoming_entities(text)
## turn any incoming ampersands into a dummy character for now. ## turn any incoming ampersands into a dummy character for now.
## This uses a negative lookahead for alphanumerics followed by a semicolon, ## This uses a negative lookahead for alphanumerics followed by a semicolon,
## implying an incoming html entity, to be skipped ## implying an incoming html entity, to be skipped
text.gsub!( /&(?![#a-z0-9]+;)/i, "x%x%" ) text.gsub!(/&(?![#a-z0-9]+;)/i, "x%x%")
end end
def no_textile( text ) def no_textile(text)
text.gsub!(/(^|\s)==([^=]+.*?)==(\s|$)?/, text.gsub!(/(^|\s)==([^=]+.*?)==(\s|$)?/,
'\1<notextile>\2</notextile>\3') '\1<notextile>\2</notextile>\3')
text.gsub!(/^ *==([^=]+.*?)==/m, text.gsub!(/^ *==([^=]+.*?)==/m,
'\1<notextile>\2</notextile>\3') '\1<notextile>\2</notextile>\3')
end end
def clean_white_space( text ) def clean_white_space(text)
# normalize line breaks # normalize line breaks
text.gsub!( "\r\n", "\n" ) text.gsub!("\r\n", "\n")
text.tr!( "\r", "\n" ) text.tr!("\r", "\n")
text.gsub!( "\t", ' ' ) text.gsub!("\t", ' ')
text.gsub!( /^ +$/, '' ) text.gsub!(/^ +$/, '')
text.gsub!( /\n{3,}/, "\n\n" ) text.gsub!(/\n{3,}/, "\n\n")
text.gsub!( /"$/, "\" " ) text.gsub!(/"$/, "\" ")
# if entire document is indented, flush # if entire document is indented, flush
# to the left side # to the left side
flush_left text flush_left text
end end
def flush_left( text ) def flush_left(text)
if /(?![\r\n\t ])[[:cntrl:]]/.match?(text) if /(?![\r\n\t ])[[:cntrl:]]/.match?(text)
text.gsub!(/(?![\r\n\t ])[[:cntrl:]]/, '') text.gsub!(/(?![\r\n\t ])[[:cntrl:]]/, '')
end end
@@ -1036,12 +1036,12 @@ class RedCloth3 < String
indt = 0 indt = 0
indt += 1 until /^ {#{indt}}\S/.match?(text) indt += 1 until /^ {#{indt}}\S/.match?(text)
if indt.nonzero? if indt.nonzero?
text.gsub!( /^ {#{indt}}/, '' ) text.gsub!(/^ {#{indt}}/, '')
end end
end end
end end
def footnote_ref( text ) def footnote_ref(text)
text.gsub!(/(?<=[\p{Word}\]])\[([0-9]+?)\](\s)?/, text.gsub!(/(?<=[\p{Word}\]])\[([0-9]+?)\](\s)?/,
'<sup><a href="#fn\1">\1</a></sup>\2') '<sup><a href="#fn\1">\1</a></sup>\2')
end end
@@ -1053,13 +1053,13 @@ class RedCloth3 < String
HASTAG_MATCH = /(<\/?\w[^\n]*?>)/m HASTAG_MATCH = /(<\/?\w[^\n]*?>)/m
ALLTAG_MATCH = /(<\/?\w[^\n]*?>)|.*?(?=<\/?\w[^\n]*?>|$)/m ALLTAG_MATCH = /(<\/?\w[^\n]*?>)|.*?(?=<\/?\w[^\n]*?>|$)/m
def glyphs_textile( text, level = 0 ) def glyphs_textile(text, level = 0)
if text !~ HASTAG_MATCH if text !~ HASTAG_MATCH
pgl text pgl text
footnote_ref text footnote_ref text
else else
codepre = 0 codepre = 0
text.gsub!( ALLTAG_MATCH ) do |line| text.gsub!(ALLTAG_MATCH) do |line|
## matches are off if we're between <code>, <pre> etc. ## matches are off if we're between <code>, <pre> etc.
if $1 if $1
if OFFTAG_OPEN.match?(line) if OFFTAG_OPEN.match?(line)
@@ -1069,9 +1069,9 @@ class RedCloth3 < String
codepre = 0 if codepre < 0 codepre = 0 if codepre < 0
end end
elsif codepre.zero? elsif codepre.zero?
glyphs_textile( line, level + 1 ) glyphs_textile(line, level + 1)
else else
htmlesc( line, :NoQuotes ) htmlesc(line, :NoQuotes)
end end
# p [level, codepre, line] # p [level, codepre, line]
@@ -1080,17 +1080,17 @@ class RedCloth3 < String
end end
end end
def rip_offtags( text, escape_aftertag=true, escape_line=true ) def rip_offtags(text, escape_aftertag=true, escape_line=true)
if text =~ /<.*>/ if text =~ /<.*>/
## strip and encode <pre> content ## strip and encode <pre> content
codepre, used_offtags = 0, {} codepre, used_offtags = 0, {}
text.gsub!( OFFTAG_MATCH ) do |line| text.gsub!(OFFTAG_MATCH) do |line|
if $3 if $3
first, offtag, aftertag = $3, $4, $5 first, offtag, aftertag = $3, $4, $5
codepre += 1 codepre += 1
used_offtags[offtag] = true used_offtags[offtag] = true
if codepre - used_offtags.length > 0 if codepre - used_offtags.length > 0
htmlesc( line, :NoQuotes ) if escape_line htmlesc(line, :NoQuotes) if escape_line
@pre_list.last << line @pre_list.last << line
line = +"" line = +""
else else
@@ -1098,7 +1098,7 @@ class RedCloth3 < String
### Regexp in formatter.rb is : /<code\s+class="(\w+)">\s?(.+)/m ### Regexp in formatter.rb is : /<code\s+class="(\w+)">\s?(.+)/m
### NB: some changes were made not to use $N variables, because we use "match" ### NB: some changes were made not to use $N variables, because we use "match"
### and it breaks following lines ### and it breaks following lines
htmlesc( aftertag, :NoQuotes ) if aftertag && escape_aftertag && !first.match(/<code\s+class="(\w+)">/) htmlesc(aftertag, :NoQuotes) if aftertag && escape_aftertag && !first.match(/<code\s+class="(\w+)">/)
line = +"<redpre##{@pre_list.length}>" line = +"<redpre##{@pre_list.length}>"
first =~ /<#{OFFTAGS}([^>]*)>/o first =~ /<#{OFFTAGS}([^>]*)>/o
tag = $1 tag = $1
@@ -1108,7 +1108,7 @@ class RedCloth3 < String
end end
elsif $1 and codepre > 0 elsif $1 and codepre > 0
if codepre - used_offtags.length > 0 if codepre - used_offtags.length > 0
htmlesc( line, :NoQuotes ) if escape_line htmlesc(line, :NoQuotes) if escape_line
@pre_list.last << line @pre_list.last << line
line = +"" line = +""
end end
@@ -1121,30 +1121,30 @@ class RedCloth3 < String
text text
end end
def smooth_offtags( text ) def smooth_offtags(text)
unless @pre_list.empty? unless @pre_list.empty?
## replace <pre> content ## replace <pre> content
text.gsub!( /<redpre#(\d+)>/ ) { @pre_list[$1.to_i] } text.gsub!(/<redpre#(\d+)>/) { @pre_list[$1.to_i] }
end end
end end
def inline( text ) def inline(text)
[/^inline_/, /^glyphs_/].each do |meth_re| [/^inline_/, /^glyphs_/].each do |meth_re|
@rules.each do |rule_name| @rules.each do |rule_name|
method( rule_name ).call( text ) if rule_name.to_s.match( meth_re ) method(rule_name).call(text) if rule_name.to_s.match(meth_re)
end end
end end
end end
def h_align( text ) def h_align(text)
H_ALGN_VALS[text] H_ALGN_VALS[text]
end end
def v_align( text ) def v_align(text)
V_ALGN_VALS[text] V_ALGN_VALS[text]
end end
def textile_popup_help( name, windowW, windowH ) def textile_popup_help(name, windowW, windowH)
' <a target="_blank" href="http://hobix.com/textile/#' + helpvar + '" onclick="window.open(this.href, \'popupwindow\', \'width=' + windowW + ',height=' + windowH + ',scrollbars,resizable\'); return false;">' + name + '</a><br />' ' <a target="_blank" href="http://hobix.com/textile/#' + helpvar + '" onclick="window.open(this.href, \'popupwindow\', \'width=' + windowW + ',height=' + windowH + ',scrollbars,resizable\'); return false;">' + name + '</a><br />'
end end
@@ -1183,16 +1183,16 @@ class RedCloth3 < String
'blockquote' => ['cite'] 'blockquote' => ['cite']
} }
def clean_html( text, tags = BASIC_TAGS ) def clean_html(text, tags = BASIC_TAGS)
text.gsub!( "<![CDATA[", '' ) text.gsub!("<![CDATA[", '')
text.gsub!( /<(\/*)(\w+)([^>]*)>/ ) do text.gsub!(/<(\/*)(\w+)([^>]*)>/) do
raw = $~ raw = $~
tag = raw[2].downcase tag = raw[2].downcase
if tags.has_key? tag if tags.has_key? tag
pcs = [tag] pcs = [tag]
tags[tag].each do |prop| tags[tag].each do |prop|
['"', "'", ''].each do |q| ['"', "'", ''].each do |q|
q2 = ( q != '' ? q : '\s' ) q2 = (q != '' ? q : '\s')
if raw[3] =~ /#{prop}\s*=\s*#{q}([^#{q2}]+)#{q}/i if raw[3] =~ /#{prop}\s*=\s*#{q}([^#{q2}]+)#{q}/i
attrv = $1 attrv = $1
next if prop == 'src' and attrv =~ %r{^(?!http)\w+:} next if prop == 'src' and attrv =~ %r{^(?!http)\w+:}

View File

@@ -510,7 +510,7 @@ class ChangesetTest < ActiveSupport::TestCase
:revision => '123', :revision => '123',
:scmid => '12345', :scmid => '12345',
:comments => str) :comments => str)
assert( c.save ) assert(c.save)
assert_equal 'Texte encodé en ISO-8859-1.', c.comments assert_equal 'Texte encodé en ISO-8859-1.', c.comments
end end
@@ -530,7 +530,7 @@ class ChangesetTest < ActiveSupport::TestCase
:scmid => '12345', :scmid => '12345',
:comments => "Texte encod\xE9 en ISO-8859-1.", :comments => "Texte encod\xE9 en ISO-8859-1.",
:committer => str2) :committer => str2)
assert( c.save ) assert(c.save)
assert_equal "Texte encod? en ISO-8859-1.", c.comments assert_equal "Texte encod? en ISO-8859-1.", c.comments
assert_equal "?a?b?c?d?e test", c.committer assert_equal "?a?b?c?d?e test", c.committer
end end
@@ -550,7 +550,7 @@ class ChangesetTest < ActiveSupport::TestCase
:revision => '123', :revision => '123',
:scmid => '12345', :scmid => '12345',
:comments => str) :comments => str)
assert( c.save ) assert(c.save)
assert_equal "test??test??", c.comments assert_equal "test??test??", c.comments
end end
@@ -577,7 +577,7 @@ class ChangesetTest < ActiveSupport::TestCase
:revision => '123', :revision => '123',
:scmid => '12345', :scmid => '12345',
:comments => s1) :comments => s1)
assert( c.save ) assert(c.save)
assert_equal s4, c.comments assert_equal s4, c.comments
end end
@@ -628,7 +628,7 @@ class ChangesetTest < ActiveSupport::TestCase
:scmid => '12345', :scmid => '12345',
:comments => nil, :comments => nil,
:committer => nil) :committer => nil)
assert( c.save ) assert(c.save)
assert_equal "", c.comments assert_equal "", c.comments
assert_nil c.committer assert_nil c.committer
assert_equal "UTF-8", c.comments.encoding.to_s assert_equal "UTF-8", c.comments.encoding.to_s
@@ -649,7 +649,7 @@ class ChangesetTest < ActiveSupport::TestCase
:scmid => '12345', :scmid => '12345',
:comments => "", :comments => "",
:committer => "") :committer => "")
assert( c.save ) assert(c.save)
assert_equal "", c.comments assert_equal "", c.comments
assert_equal "", c.committer assert_equal "", c.committer
assert_equal "UTF-8", c.comments.encoding.to_s assert_equal "UTF-8", c.comments.encoding.to_s

View File

@@ -53,7 +53,7 @@ class IssueSubtaskingTest < ActiveSupport::TestCase
with_settings :parent_issue_dates => 'derived' do with_settings :parent_issue_dates => 'derived' do
parent = Issue.generate! parent = Issue.generate!
parent.generate_child!(:start_date => '2010-01-25', :due_date => '2010-02-15') parent.generate_child!(:start_date => '2010-01-25', :due_date => '2010-02-15')
parent.generate_child!( :due_date => '2010-02-13') parent.generate_child!(:due_date => '2010-02-13')
parent.generate_child!(:start_date => '2010-02-01', :due_date => '2010-02-22') parent.generate_child!(:start_date => '2010-02-01', :due_date => '2010-02-22')
parent.reload parent.reload
assert_equal Date.parse('2010-01-25'), parent.start_date assert_equal Date.parse('2010-01-25'), parent.start_date

View File

@@ -59,7 +59,7 @@ class PdfTest < ActiveSupport::TestCase
def test_rdm_pdf_iconv_invalid_utf8_should_be_replaced_ja def test_rdm_pdf_iconv_invalid_utf8_should_be_replaced_ja
str1 = "Texte encod\xE9 en ISO-8859-1" str1 = "Texte encod\xE9 en ISO-8859-1"
str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test".b str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test".b
encoding = ( RUBY_PLATFORM == 'java' ? "SJIS" : "CP932" ) encoding = (RUBY_PLATFORM == 'java' ? "SJIS" : "CP932")
txt_1 = Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(str1, encoding) txt_1 = Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(str1, encoding)
txt_2 = Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(str2, encoding) txt_2 = Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(str2, encoding)
assert_equal "ASCII-8BIT", txt_1.encoding.to_s assert_equal "ASCII-8BIT", txt_1.encoding.to_s