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.freeze
- GITHUB_REF_REGEX =
%r{ (?:https?://)? github\.com/(?<repo>#{GITHUB_USERNAME}/[^/\s]+)/ (?:issue|pull)s?/(?<number>\d+) }x.freeze
- MENTION_REGEX =
%r{(?<![A-Za-z0-9`~])@#{GITHUB_USERNAME}/?}.freeze
- EOS_REGEX =
End of string
/\z/.freeze
- 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) ⇒ Object
Constructor Details
#initialize(github_redirection_service:) ⇒ LinkAndMentionSanitizer
Returns a new instance of LinkAndMentionSanitizer.
29 30 31 |
# File 'lib/dependabot/pull_request_creator/message_builder/link_and_mention_sanitizer.rb', line 29 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.
27 28 29 |
# File 'lib/dependabot/pull_request_creator/message_builder/link_and_mention_sanitizer.rb', line 27 def github_redirection_service @github_redirection_service end |
Instance Method Details
#sanitize_links_and_mentions(text:, unsafe: false) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/dependabot/pull_request_creator/message_builder/link_and_mention_sanitizer.rb', line 33 def sanitize_links_and_mentions(text:, unsafe: false) doc = CommonMarker.render_doc( text, :LIBERAL_HTML_TAG, COMMONMARKER_EXTENSIONS ) sanitize_mentions(doc) sanitize_links(doc) mode = unsafe ? :UNSAFE : :DEFAULT doc.to_html(([mode] + COMMONMARKER_OPTIONS), COMMONMARKER_EXTENSIONS) end |