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 =
We rely on GitHub to do the HTML sanitization
%i( UNSAFE 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:) ⇒ Object
Constructor Details
#initialize(github_redirection_service:) ⇒ LinkAndMentionSanitizer
Returns a new instance of LinkAndMentionSanitizer.
30 31 32 |
# File 'lib/dependabot/pull_request_creator/message_builder/link_and_mention_sanitizer.rb', line 30 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.
28 29 30 |
# File 'lib/dependabot/pull_request_creator/message_builder/link_and_mention_sanitizer.rb', line 28 def github_redirection_service @github_redirection_service end |
Instance Method Details
#sanitize_links_and_mentions(text:) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/dependabot/pull_request_creator/message_builder/link_and_mention_sanitizer.rb', line 34 def sanitize_links_and_mentions(text:) doc = CommonMarker.render_doc( text, :LIBERAL_HTML_TAG, COMMONMARKER_EXTENSIONS ) sanitize_mentions(doc) sanitize_links(doc) doc.to_html(COMMONMARKER_OPTIONS, COMMONMARKER_EXTENSIONS) end |