Class: Dependabot::PullRequestCreator::MessageBuilder::LinkAndMentionSanitizer
- Inherits:
-
Object
- Object
- Dependabot::PullRequestCreator::MessageBuilder::LinkAndMentionSanitizer
- Defined in:
- lib/dependabot/pull_request_creator/message_builder/link_and_mention_sanitizer.rb
Constant Summary collapse
- GITHUB_USERNAME =
/[a-z0-9]+(-[a-z0-9]+)*/i
- GITHUB_REF_REGEX =
%r{ (?:https?://)? github\.com/(?<repo>#{GITHUB_USERNAME}/[^/\s]+)/ (?:issue|pull)s?/(?<number>\d+) }x
- GITHUB_NWO_REGEX =
[^/s#]+ means one or more characters not matching (^) the class /, whitespace (s), or #
%r{(?<repo>#{GITHUB_USERNAME}/[^/\s#]+)#(?<number>\d+)}
- MENTION_REGEX =
%r{(?<![A-Za-z0-9`~])@#{GITHUB_USERNAME}/?}
- TEAM_MENTION_REGEX =
regex to match a team mention on github
%r{(?<![A-Za-z0-9`~])@(?<org>#{GITHUB_USERNAME})/(?<team>#{GITHUB_USERNAME})/?}
- EOS_REGEX =
End of string
/\z/
- COMMONMARKER_OPTIONS =
%i( GITHUB_PRE_LANG FULL_INFO_STRING ).freeze
- COMMONMARKER_EXTENSIONS =
%i( table tasklist strikethrough autolink tagfilter ).freeze
Instance Attribute Summary collapse
-
#github_redirection_service ⇒ Object
readonly
Returns the value of attribute github_redirection_service.
Instance Method Summary collapse
-
#initialize(github_redirection_service:) ⇒ LinkAndMentionSanitizer
constructor
A new instance of LinkAndMentionSanitizer.
- #sanitize_links_and_mentions(text:, unsafe: false, format_html: true) ⇒ Object
Constructor Details
#initialize(github_redirection_service:) ⇒ LinkAndMentionSanitizer
Returns a new instance of LinkAndMentionSanitizer.
34 35 36 |
# File 'lib/dependabot/pull_request_creator/message_builder/link_and_mention_sanitizer.rb', line 34 def initialize(github_redirection_service:) @github_redirection_service = github_redirection_service end |
Instance Attribute Details
#github_redirection_service ⇒ Object (readonly)
Returns the value of attribute github_redirection_service.
32 33 34 |
# File 'lib/dependabot/pull_request_creator/message_builder/link_and_mention_sanitizer.rb', line 32 def github_redirection_service @github_redirection_service end |
Instance Method Details
#sanitize_links_and_mentions(text:, unsafe: false, format_html: true) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/dependabot/pull_request_creator/message_builder/link_and_mention_sanitizer.rb', line 38 def sanitize_links_and_mentions(text:, unsafe: false, format_html: true) doc = CommonMarker.render_doc( text, :LIBERAL_HTML_TAG, COMMONMARKER_EXTENSIONS ) sanitize_team_mentions(doc) sanitize_mentions(doc) sanitize_links(doc) sanitize_nwo_text(doc) mode = unsafe ? :UNSAFE : :DEFAULT return doc.to_commonmark([mode] + COMMONMARKER_OPTIONS) unless format_html doc.to_html(([mode] + COMMONMARKER_OPTIONS), COMMONMARKER_EXTENSIONS) end |