Project

General

Profile

Defect #28322 ยป 0001-Don-t-match-commit-references-across-new-lines.patch

Gregor Schmidt, 2018-03-12 09:49

View differences:

app/models/changeset.rb
125 125

  
126 126
    referenced_issues = []
127 127

  
128
    comments.scan(/([\s\(\[,-]|^)((#{kw_regexp})[\s:]+)?(#\d+(\s+@#{TIMELOG_RE})?([\s,;&]+#\d+(\s+@#{TIMELOG_RE})?)*)(?=[[:punct:]]|\s|<|$)/i) do |match|
128
    comments.scan(/([[[:blank:]]\(\[,-]|^)((#{kw_regexp})[[[:blank:]]:]+)?(#\d+([[:blank:]]+@#{TIMELOG_RE})?([[[:blank:]],;&]+#\d+([[:blank:]]+@#{TIMELOG_RE})?)*)(?=[[:punct:]]|[[:blank:]]|<|$)/i) do |match|
129 129
      action, refs = match[2].to_s.downcase, match[3]
130 130
      next unless action.present? || ref_keywords_any
131 131

  
132
      refs.scan(/#(\d+)(\s+@#{TIMELOG_RE})?/).each do |m|
132
      refs.scan(/#(\d+)([[:blank:]]+@#{TIMELOG_RE})?/).each do |m|
133 133
        issue, hours = find_referenced_issue_by_id(m[0].to_i), m[2]
134 134
        if issue && !issue_linked_to_same_commit?(issue)
135 135
          referenced_issues << issue
test/unit/changeset_test.rb
60 60
    assert_equal [1], c.issue_ids.sort
61 61
  end
62 62

  
63
  def test_ref_keywords_stop_at_newlines
64
    ActionMailer::Base.deliveries.clear
65
    Setting.commit_ref_keywords = '*'
66
    Setting.commit_update_keywords = [{'keywords' => 'fixes', 'status_id' => '5'}]
67

  
68
    c = Changeset.new(:repository   => Project.find(1).repository,
69
                      :committed_on => Time.now,
70
                      :comments     => "#1 some UI fixes\n#2 still work in progess",
71
                      :revision     => '12345')
72
    assert c.save
73
    assert_equal [1, 2], c.issue_ids.sort
74
    wip = Issue.find(2)
75
    assert !wip.closed?
76
    assert_empty ActionMailer::Base.deliveries
77
  end
78

  
63 79
  def test_ref_keywords_any_only
64 80
    Setting.commit_ref_keywords = '*'
65 81
    Setting.commit_update_keywords = ''
    (1-1/1)