Project

General

Profile

Patch #24382 » parse_redmine_links_regexp_simplify.patch

Dmitry Lisichkin, 2016-11-16 12:32

View differences:

app/helpers/application_helper.rb (revision )
768 768
  #     identifier:version:1.0.0
769 769
  #     identifier:source:some/file
770 770
  def parse_redmine_links(text, default_project, obj, attr, only_path, options)
771
    text.gsub!(%r{<a( [^>]+?)?>(.*?)</a>|([\s\(,\-\[\>]|^)(!)?(([a-z0-9\-_]+):)?(attachment|document|version|forum|news|message|project|commit|source|export)?(((#)|((([a-z0-9\-_]+)\|)?(r)))((\d+)((#note)?-(\d+))?)|(:)([^"\s<>][^\s<>]*?|"[^"]+?"))(?=(?=[[:punct:]][^A-Za-z0-9_/])|,|\s|\]|<|$)}) do |m|
772
      tag_content, leading, esc, project_prefix, project_identifier, prefix, repo_prefix, repo_identifier, sep, identifier, comment_suffix, comment_id = $2, $3, $4, $5, $6, $7, $12, $13, $10 || $14 || $20, $16 || $21, $17, $19
771
    text.gsub!(LINKS_RE) do |_|
772
      tag_content = $~[:tag_content]
773
      leading = $~[:leading]
774
      esc = $~[:esc]
775
      project_prefix = $~[:project_prefix]
776
      project_identifier = $~[:project_identifier]
777
      prefix = $~[:prefix]
778
      repo_prefix = $~[:repo_prefix]
779
      repo_identifier = $~[:repo_identifier]
780
      sep = $~[:sep1] || $~[:sep2] || $~[:sep3]
781
      identifier = $~[:identifier1] || $~[:identifier2]
782
      comment_suffix = $~[:comment_suffix]
783
      comment_id = $~[:comment_id]
784

  
773 785
      if tag_content
774 786
        $&
775 787
      else
......
904 916
    end
905 917
  end
906 918

  
919
  LINKS_RE =
920
      %r{
921
            <a(?<tag_content> [^>]+?)?>(.*?)</a>|
922
            (?<leading>[\s\(,\-\[\>]|^)
923
            (?<esc>!)?
924
            (?<project_prefix>(?<project_identifier>[a-z0-9\-_]+):)?
925
            (?<prefix>attachment|document|version|forum|news|message|project|commit|source|export)?
926
            (
927
              (
928
                (?<sep1>\#)|
929
                (
930
                  (?<repo_prefix>(?<repo_identifier>[a-z0-9\-_]+)\|)?
931
                  (?<sep2>r)
932
                )
933
              )
934
              (
935
                (?<identifier1>\d+)
936
                (?<comment_suffix>
937
                  (\#note)?
938
                  -(?<comment_id>\d+)
939
                )?
940
              )|
941
              (?<sep3>:)
942
              (?<identifier2>[^"\s<>][^\s<>]*?|"[^"]+?")
943
            )
944
            (?=
945
              (?=[[:punct:]][^A-Za-z0-9_/])|
946
              ,|
947
              \s|
948
              \]|
949
              <|
950
              $
951
            )
952
      }x
907 953
  HEADING_RE = /(<h(\d)( [^>]+)?>(.+?)<\/h(\d)>)/i unless const_defined?(:HEADING_RE)
908 954

  
909 955
  def parse_sections(text, project, obj, attr, only_path, options)
(1-1/2)