dependabot-common 0.113.8 → 0.113.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e237dcfe1f60fe9dc9e264f5119d916c6498bf11180ab832067f8f50e40053c4
4
- data.tar.gz: 739ba909c900ebc9635ff04f312237e6c3e3f9a66e651da9194c66df83bda86e
3
+ metadata.gz: d7dc4bc4e7243b5783878592692ff326a7d2f80f6d4c6f97d51234353fd5d8f8
4
+ data.tar.gz: '0274587f10ad8b81fa768804d5300177b3b7919e67235142ac4a8e9cf07a885e'
5
5
  SHA512:
6
- metadata.gz: a2e013639daedfa94637e55ad67e54c6e1be464ea6e2bc4074831cc939e311ed71c8b8aa86502770f0762d311b2fdefb9618b5a59ab57e2e0113a7a6d0a5296d
7
- data.tar.gz: 51ba82962b4df0eeb9700c80763d791315ceb4f09fcaed69cc5d4d7921a6564ffef716fd2dc01fc69d177c15bd956516f766d1f6ee77a22d802323dc1b8a4859
6
+ metadata.gz: 5e23b2228c629a3b23acf1dd4ebf278201f7dd8d4005b3f643099bb7f563389d67a27ce8130848ce881cb8cb5d2e4c5306439157fca2567e3bd25853c204c1f6
7
+ data.tar.gz: 4ecf0ef7609d7cd88a0481f373cdbad1d98adec373e922a16556a738d4a4ed912c479da0fa484cb6e806738cbfc934b4aa21a166f8b1754beae9cf2caf0c11f4
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "strscan"
3
4
  require "dependabot/pull_request_creator/message_builder"
4
5
 
5
6
  module Dependabot
@@ -12,18 +13,9 @@ module Dependabot
12
13
  github\.com/(?<repo>#{GITHUB_USERNAME}/[^/\s]+)/
13
14
  (?:issue|pull)s?/(?<number>\d+)
14
15
  }x.freeze
15
-
16
- # Note that we're being deliberately careful about not matching
17
- # different length strings of what look like code block quotes. By
18
- # doing so we err on the side of sanitizing, which is *much* better
19
- # than accidentally not sanitizing.
20
- #
21
- # rubocop:disable Style/RegexpLiteral
22
- CODEBLOCK_REGEX = %r{
23
- (?=[\s]`{3}[^`])|(?=[\s]`{3}\Z)|(?=\A`{3}[^`])|
24
- (?=[\s]~{3}[^~])|(?=[\s]~{3}\Z)|(?=\A~{3}[^~])
25
- }x.freeze
26
- # rubocop:enable Style/RegexpLiteral
16
+ CODEBLOCK_REGEX = /(`+).*?(\1)|~~~.*?~~~/m.freeze
17
+ # End of string
18
+ EOS_REGEX = /\z/.freeze
27
19
 
28
20
  attr_reader :github_redirection_service
29
21
 
@@ -33,22 +25,35 @@ module Dependabot
33
25
 
34
26
  def sanitize_links_and_mentions(text:)
35
27
  # We don't want to sanitize any links or mentions that are contained
36
- # within code blocks, so we split the text on "```"
37
- snippets = text.split(CODEBLOCK_REGEX)
38
- if snippets.first&.start_with?(CODEBLOCK_REGEX)
39
- snippets = ["", *snippets]
28
+ # within code blocks, so we split the text on "```" or "~~~"
29
+ sanitized_text = []
30
+ scan = StringScanner.new(text)
31
+ until scan.eos?
32
+ block = scan.scan_until(CODEBLOCK_REGEX) ||
33
+ scan.scan_until(EOS_REGEX)
34
+ sanitized_text << sanitize_links_and_mentions_in_block(block)
40
35
  end
41
-
42
- snippets.map.with_index do |snippet, index|
43
- next snippet if index.odd?
44
-
45
- snippet = sanitize_mentions(snippet)
46
- sanitize_links(snippet)
47
- end.join
36
+ sanitized_text.join
48
37
  end
49
38
 
50
39
  private
51
40
 
41
+ def sanitize_links_and_mentions_in_block(block)
42
+ # Handle code blocks one by one
43
+ normal_text = block
44
+ verbatim_text = ""
45
+ match = block.match(CODEBLOCK_REGEX)
46
+ if match
47
+ # Part leading up to start of code block
48
+ normal_text = match.pre_match
49
+ # Entire code block copied verbatim
50
+ verbatim_text = match.to_s
51
+ end
52
+ normal_text = sanitize_mentions(normal_text)
53
+ normal_text = sanitize_links(normal_text)
54
+ normal_text + verbatim_text
55
+ end
56
+
52
57
  def sanitize_mentions(text)
53
58
  text.gsub(%r{(?<![A-Za-z0-9`~])@#{GITHUB_USERNAME}/?}) do |mention|
54
59
  next mention if mention.end_with?("/")
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dependabot
4
- VERSION = "0.113.8"
4
+ VERSION = "0.113.13"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dependabot-common
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.113.8
4
+ version: 0.113.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dependabot
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-02 00:00:00.000000000 Z
11
+ date: 2019-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-codecommit