bundler 4.1.0.beta3 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/lib/bundler/build_metadata.rb +2 -2
  3. data/lib/bundler/checksum.rb +8 -2
  4. data/lib/bundler/cli/clean.rb +19 -3
  5. data/lib/bundler/cli/exec.rb +1 -1
  6. data/lib/bundler/cli/install.rb +1 -1
  7. data/lib/bundler/cli/lock.rb +12 -0
  8. data/lib/bundler/cli/update.rb +1 -1
  9. data/lib/bundler/cli.rb +2 -0
  10. data/lib/bundler/definition.rb +125 -3
  11. data/lib/bundler/dsl.rb +6 -2
  12. data/lib/bundler/errors.rb +8 -0
  13. data/lib/bundler/fetcher/downloader.rb +7 -3
  14. data/lib/bundler/index.rb +7 -2
  15. data/lib/bundler/inline.rb +16 -8
  16. data/lib/bundler/installer.rb +19 -0
  17. data/lib/bundler/lazy_specification.rb +42 -25
  18. data/lib/bundler/lockfile_generator.rb +21 -9
  19. data/lib/bundler/lockfile_parser.rb +21 -5
  20. data/lib/bundler/man/bundle-lock.1 +7 -1
  21. data/lib/bundler/man/bundle-lock.1.ronn +10 -0
  22. data/lib/bundler/man/bundle-plugin.1 +61 -0
  23. data/lib/bundler/man/bundle-plugin.1.ronn +84 -0
  24. data/lib/bundler/man/gemfile.5 +3 -1
  25. data/lib/bundler/man/gemfile.5.ronn +11 -3
  26. data/lib/bundler/match_platform.rb +3 -3
  27. data/lib/bundler/mirror.rb +7 -5
  28. data/lib/bundler/resolver.rb +2 -0
  29. data/lib/bundler/ruby_dsl.rb +2 -1
  30. data/lib/bundler/rubygems_ext.rb +41 -9
  31. data/lib/bundler/rubygems_integration.rb +2 -4
  32. data/lib/bundler/runtime.rb +24 -10
  33. data/lib/bundler/source/git/git_proxy.rb +18 -6
  34. data/lib/bundler/source/git.rb +0 -2
  35. data/lib/bundler/spec_set.rb +26 -7
  36. data/lib/bundler/stub_specification.rb +4 -0
  37. data/lib/bundler/version.rb +1 -1
  38. data/lib/bundler/worker.rb +4 -0
  39. data/lib/bundler.rb +1 -1
  40. data/lib/rubygems/compact_index_client/http_fetcher.rb +3 -1
  41. data/lib/rubygems/yaml_serializer.rb +128 -46
  42. metadata +2 -2
@@ -24,23 +24,29 @@ module Gem
24
24
  class Parser
25
25
  # A plain (unquoted) mapping key followed by ":". "#" inside a key is
26
26
  # literal unless preceded by a space (which would start a comment).
27
- MAPPING_KEY_RE = /\G((?:[^#:\s]|:[^ ])(?:[^#:]|:[^ ]|(?<=[^ ])#)*):(?:[ ]+(.*))?$/
27
+ # Like Psych, spaces and tabs may separate the ":" from the value.
28
+ MAPPING_KEY_RE = /\G((?:[^#:\s]|:[^ \t])(?:[^#:]|:[^ \t]|(?<=[^ ])#)*):(?:[ \t]+(.*))?$/
28
29
  # A quoted mapping key followed by ":". A whole-line quoted scalar
29
30
  # cannot match because its closing quote is at the end of the line.
30
- QUOTED_KEY_RE = /\G("(?:[^"\\]|\\.)*"|'(?:[^']|'')*'):(?:[ ]+(.*))?$/
31
+ QUOTED_KEY_RE = /\G("(?:[^"\\]|\\.)*"|'(?:[^']|'')*'):(?:[ \t]+(.*))?$/
31
32
  # An entry of a flow sequence. A quoted entry may contain commas.
32
33
  FLOW_SEQUENCE_ENTRY_RE = /"(?:[^"\\]|\\.)*"|'(?:[^']|'')*'|[^,\s](?:[^,]*[^,\s])?/
33
34
  SEQUENCE_ENTRY_RE = /\G-(?: |\z)/
35
+ # A quoted scalar whose closing quote is on a later line.
36
+ OPEN_QUOTED_RE = /\A(?:! )?(?:"(?>(?:[^"\\]|\\.)*)(\\)?|'(?>(?:[^']|'')*))\z/
34
37
  RUBY_OBJECT_TAG_RE = %r{\G!ruby/object:}
35
38
  LSTRIP_BYTES = [0, 9, 10, 11, 12, 13, 32].freeze
39
+ UTF8_BOM_BYTES = [0xEF, 0xBB, 0xBF].freeze
36
40
  MAX_NESTING_DEPTH = 1_000
37
41
  NULL_SCALARS = %w[~ null].freeze
38
42
  BLANK_RE = /\A[\0\s]*\z/
39
43
  BLANK_OR_COMMENT_RE = /\A[\0\s]*(?:#|\z)/
44
+ DOCUMENT_END_RE = /\A\.\.\.(?:[ \t]|\z)/
40
45
 
41
46
  STRING_UNESCAPES = {
42
47
  "\\\\" => "\\",
43
48
  "\\\"" => "\"",
49
+ "\\ " => " ",
44
50
  "\\0" => "\0",
45
51
  "\\a" => "\a",
46
52
  "\\b" => "\b",
@@ -57,9 +63,18 @@ module Gem
57
63
  }.freeze
58
64
 
59
65
  def initialize(source)
60
- @lines = source.split(/\r?\n/).each(&:freeze)
66
+ raise TypeError, "no implicit conversion of nil into String" if source.nil?
67
+
68
+ source = strip_bom(source)
69
+ # Keep trailing empty lines, which a block scalar with keep chomping
70
+ # ("|+") preserves, but not the empty string after the final line
71
+ # break.
72
+ @lines = source.split(/\r?\n/, -1)
73
+ @lines.pop if @lines.last == ""
74
+ @lines.each(&:freeze)
61
75
  @anchors = {}
62
76
  @depth = 0
77
+ strip_document_end
63
78
  strip_document_prefix
64
79
  end
65
80
 
@@ -83,6 +98,19 @@ module Gem
83
98
 
84
99
  private
85
100
 
101
+ # Byte-wise, as checksums.yaml is read as binary unlike config files,
102
+ # and binary cannot be compared with a UTF-8 string holding the BOM.
103
+ def strip_bom(source)
104
+ return source unless UTF8_BOM_BYTES.each_with_index.all? {|byte, i| source.getbyte(i) == byte }
105
+
106
+ source.byteslice(UTF8_BOM_BYTES.size..)
107
+ end
108
+
109
+ def strip_document_end
110
+ index = @lines.index {|line| DOCUMENT_END_RE.match?(line) }
111
+ @lines.slice!(index..) if index
112
+ end
113
+
86
114
  def strip_document_prefix
87
115
  return if @lines.empty?
88
116
  return unless @lines[0]&.start_with?("---")
@@ -109,8 +137,11 @@ module Gem
109
137
 
110
138
  pos = indent
111
139
  if /\G&/.match?(line, indent) && (anchor = consume_anchor)
140
+ # A lone anchor line, e.g. "--- &1", anchors the node on the next line.
141
+ skip_blank_and_comments
142
+ return register_anchor(anchor, nil) if @lines.empty? || current_indent < base_indent
112
143
  line = @lines[0]
113
- pos = indent_of(line)
144
+ indent = pos = indent_of(line)
114
145
  end
115
146
 
116
147
  if SEQUENCE_ENTRY_RE.match?(line, pos)
@@ -149,7 +180,7 @@ module Gem
149
180
  content = line[indent + 1, line.size]
150
181
  content.strip!
151
182
  item_anchor = nil
152
- item_anchor, content = extract_item_anchor(content) if content.start_with?("&")
183
+ item_anchor, content = extract_anchor(content) if content.start_with?("&")
153
184
  item = parse_sequence_item(content, indent)
154
185
  items << register_anchor(item_anchor, item)
155
186
  end
@@ -161,7 +192,7 @@ module Gem
161
192
  parse_inline_alias(content)
162
193
  elsif content.empty?
163
194
  skip_blank_and_comments
164
- @lines.any? && current_indent > indent ? parse_node(indent) : nil
195
+ @lines.any? && current_indent > indent ? parse_node(indent + 1) : nil
165
196
  elsif content.start_with?("!ruby/object:")
166
197
  parse_tagged_content(content.strip, indent)
167
198
  elsif content.start_with?("!binary ")
@@ -170,7 +201,8 @@ module Gem
170
201
  @lines.unshift("#{" " * (indent + 2)}#{content}")
171
202
  parse_node(indent)
172
203
  elsif QUOTED_KEY_RE.match?(content) ||
173
- (MAPPING_KEY_RE.match?(content) && !content.start_with?("!ruby/object:"))
204
+ (MAPPING_KEY_RE.match?(content) && !content.start_with?("!ruby/object:") &&
205
+ !OPEN_QUOTED_RE.match?(content))
174
206
  @lines.unshift("#{" " * (indent + 2)}#{content}")
175
207
  parse_node(indent)
176
208
  elsif content.start_with?("|")
@@ -203,7 +235,7 @@ module Gem
203
235
  val = strip_comment(val || "")
204
236
 
205
237
  val_anchor = nil
206
- val_anchor, val = consume_value_anchor(val) if val.start_with?("&")
238
+ val_anchor, val = extract_anchor(val) if val.start_with?("&")
207
239
  value = parse_mapping_value(val, indent)
208
240
  value = register_anchor(val_anchor, value) if val_anchor
209
241
 
@@ -280,7 +312,11 @@ module Gem
280
312
  end
281
313
 
282
314
  res = parts.join
283
- res.delete_suffix!("\n") while chomping == "-" && res.end_with?("\n")
315
+ unless chomping == "+"
316
+ res.delete_suffix!("\n") while res.end_with?("\n")
317
+ # Clipping keeps the final line break but drops trailing empty lines.
318
+ res << "\n" if chomping.nil? && !res.empty?
319
+ end
284
320
  res
285
321
  end
286
322
 
@@ -304,13 +340,28 @@ module Gem
304
340
  def fold_continuation_lines(result, val, indent)
305
341
  return unless result.is_a?(String)
306
342
 
307
- # "#" does not start a comment inside a quoted scalar that runs onto the next lines.
308
- stop = val.start_with?("'", "\"") && result == val ? BLANK_RE : BLANK_OR_COMMENT_RE
309
- while @lines.any? && !stop.match?(@lines[0]) && current_indent > indent
343
+ return result.replace(fold_quoted_lines(val.delete_prefix("! "), indent)) if OPEN_QUOTED_RE.match?(val)
344
+
345
+ while @lines.any? && !BLANK_OR_COMMENT_RE.match?(@lines[0]) && current_indent > indent
310
346
  result << " " << @lines.shift.strip
311
347
  end
312
348
  end
313
349
 
350
+ def fold_quoted_lines(val, indent)
351
+ open = OPEN_QUOTED_RE.match(val)
352
+ breaks = +""
353
+ while open && @lines.any? && (BLANK_RE.match?(@lines[0]) || current_indent > indent)
354
+ line = @lines.shift.strip
355
+ next breaks << "\n" if line.empty?
356
+
357
+ val.chop! if open[1]
358
+ val << (breaks.empty? && !open[1] ? " " : breaks) << line
359
+ breaks.clear
360
+ open = OPEN_QUOTED_RE.match("#{val[0]}#{line}")
361
+ end
362
+ coerce(val)
363
+ end
364
+
314
365
  def coerce(val, depth = 0)
315
366
  raise_max_nesting! if depth > MAX_NESTING_DEPTH
316
367
 
@@ -319,7 +370,7 @@ module Gem
319
370
  if val.size >= 2 && val.start_with?("\"") && val.end_with?("\"")
320
371
  inner = val[1..-2]
321
372
  return inner unless inner.include?("\\")
322
- inner.gsub(/\\(?:["\\0abtnvfreN_LP]|x\h{2}|u\h{4}|U\h{8})/) do |m|
373
+ inner.gsub(/\\(?:["\\ 0abtnvfreN_LP]|x\h{2}|u\h{4}|U\h{8})/) do |m|
323
374
  char = STRING_UNESCAPES[m] || unescape_code_point(m)
324
375
  # Metadata is read as binary, where non-ASCII text stays as UTF-8 bytes.
325
376
  Encoding.compatible?(inner, char) ? char : char.b
@@ -401,29 +452,28 @@ module Gem
401
452
  def consume_anchor
402
453
  line = @lines[0]
403
454
  stripped = line.lstrip
404
- return nil unless stripped.start_with?("&") && stripped =~ /^&(\S+)\s+/
455
+ return nil unless stripped.start_with?("&") && stripped =~ /^&(\S+)\s*/
405
456
 
406
457
  anchor = $1
407
- @lines[0] = line.sub(/&#{Regexp.escape(anchor)}\s+/, "")
458
+ if $'.empty?
459
+ @lines.shift
460
+ else
461
+ @lines[0] = line.sub(/&#{Regexp.escape(anchor)}\s+/, "")
462
+ end
408
463
  anchor
409
464
  end
410
465
 
411
- def extract_item_anchor(content)
466
+ def extract_anchor(content)
412
467
  return [nil, content] unless content =~ /^&(\S+)/
413
468
 
414
469
  anchor = $1
415
470
  [anchor, content.sub(/^&#{Regexp.escape(anchor)}\s*/, "")]
416
471
  end
417
472
 
418
- def consume_value_anchor(val)
419
- return [nil, val] unless val =~ /^&(\S+)\s+/
420
-
421
- anchor = $1
422
- [anchor, val.sub(/^&#{Regexp.escape(anchor)}\s+/, "")]
423
- end
424
-
425
473
  def register_anchor(name, node)
426
474
  if name
475
+ # An anchored empty node still defines the anchor, as a null.
476
+ node ||= Scalar.new(nil)
427
477
  @anchors[name] = node
428
478
  node.anchor = name if node.respond_to?(:anchor=)
429
479
  end
@@ -483,14 +533,16 @@ module Gem
483
533
  class Builder
484
534
  VALID_OPS = %w[= != > < >= <= ~>].freeze
485
535
  ARRAY_FIELDS = %w[files test_files executables extra_rdoc_files].freeze
486
- MAX_ALIAS_RESOLUTIONS = 1_000
536
+ MAX_ALIAS_EXPANSION = 100_000
487
537
 
488
538
  def initialize(permitted_classes: [], permitted_symbols: [], aliases: true)
489
539
  @permitted_classes = permitted_classes.map {|c| "!ruby/object:#{c}" }
490
540
  @permitted_symbols = permitted_symbols
491
541
  @aliases = aliases
492
542
  @anchor_values = {}
493
- @alias_count = 0
543
+ @anchor_sizes = {}
544
+ @expanded_size = 0
545
+ @alias_expansion = 0
494
546
  end
495
547
 
496
548
  def build(node)
@@ -508,31 +560,40 @@ module Gem
508
560
  private
509
561
 
510
562
  def build_node(node)
563
+ start = @expanded_size
511
564
  case node
512
565
  when nil then nil
513
566
  when AliasRef then resolve_alias(node)
514
- when Scalar then store_anchor(node.anchor, node.value)
515
- when Mapping then build_mapping(node)
516
- when Sequence then store_anchor(node.anchor, node.items.map {|item| build_node(item) })
567
+ when Scalar then store_anchor(node.anchor, node.value, start)
568
+ when Mapping then store_anchor(node.anchor, build_mapping(node), start)
569
+ when Sequence then store_anchor(node.anchor, node.items.map {|item| build_node(item) }, start)
517
570
  else node # already a Ruby object
518
571
  end
519
572
  end
520
573
 
521
574
  def resolve_alias(node)
522
575
  raise Psych::AliasesNotEnabled unless @aliases
523
- @alias_count += 1
524
- if @alias_count > MAX_ALIAS_RESOLUTIONS
525
- raise Psych::BadAlias, "exceeded maximum alias resolutions (#{MAX_ALIAS_RESOLUTIONS})"
526
- end
527
576
  unless @anchor_values.key?(node.name)
528
- klass = defined?(Psych::AnchorNotDefined) ? Psych::AnchorNotDefined : Psych::BadAlias
529
- raise klass, "An alias referenced an unknown anchor: #{node.name}"
577
+ raise Psych::AnchorNotDefined, node.name if defined?(Psych::AnchorNotDefined)
578
+ raise Psych::BadAlias, "An alias referenced an unknown anchor: #{node.name}"
579
+ end
580
+ # Charge the expanded size of the anchor, weighing scalars by length,
581
+ # so neither nested aliases nor aliases to a long string blow up.
582
+ size = @anchor_sizes.fetch(node.name)
583
+ @expanded_size += size
584
+ @alias_expansion += size
585
+ if @alias_expansion > MAX_ALIAS_EXPANSION
586
+ raise Psych::BadAlias, "exceeded maximum alias expansion (#{MAX_ALIAS_EXPANSION})"
530
587
  end
531
588
  @anchor_values.fetch(node.name)
532
589
  end
533
590
 
534
- def store_anchor(name, value)
535
- @anchor_values[name] = value if name
591
+ def store_anchor(name, value, start)
592
+ @expanded_size += value.is_a?(String) ? 1 + value.bytesize : 1
593
+ if name
594
+ @anchor_values[name] = value
595
+ @anchor_sizes[name] = @expanded_size - start
596
+ end
536
597
  value
537
598
  end
538
599
 
@@ -558,7 +619,7 @@ module Gem
558
619
  raise ArgumentError, "undefined class/module #{node.tag.sub("!ruby/object:", "")}"
559
620
  end
560
621
 
561
- store_anchor(node.anchor, result)
622
+ result
562
623
  end
563
624
 
564
625
  def build_hash(node)
@@ -741,7 +802,9 @@ module Gem
741
802
  }.freeze
742
803
 
743
804
  def emit(obj)
744
- "---#{emit_node(obj, 0)}"
805
+ res = "---#{emit_node(obj, 0)}"
806
+ res << "...\n" if @open_ended
807
+ res
745
808
  end
746
809
 
747
810
  private
@@ -859,15 +922,35 @@ module Gem
859
922
  end
860
923
 
861
924
  def emit_block_scalar(str, indent)
862
- parts = [str.end_with?("\n") ? " |\n" : " |-\n"]
925
+ # The root node has no parent to be indented from, so indent its
926
+ # content by one level like libyaml does.
927
+ indent = 2 if indent.zero?
928
+ parts = [" |#{block_scalar_header(str)}\n"]
863
929
  str.each_line do |line|
864
- parts << "#{pad(indent + 2)}#{line}"
930
+ parts << (line == "\n" ? line : "#{pad(indent)}#{line}")
865
931
  end
866
932
  res = parts.join
867
933
  res << "\n" unless res.end_with?("\n")
868
934
  res
869
935
  end
870
936
 
937
+ # Mirrors libyaml: an explicit indentation indicator when the first
938
+ # line is empty or starts with a space (a parser would otherwise take
939
+ # that whitespace as the block indentation and drop it), "-" when the
940
+ # content does not end with a line break and "+" when it ends with
941
+ # more than one, which also requires a document end marker.
942
+ def block_scalar_header(str)
943
+ header = +""
944
+ header << "2" if str.start_with?(" ", "\n")
945
+ if !str.end_with?("\n")
946
+ header << "-"
947
+ elsif str.end_with?("\n\n") || str == "\n"
948
+ header << "+"
949
+ @open_ended = true
950
+ end
951
+ header
952
+ end
953
+
871
954
  def needs_quoting?(str, quote = false)
872
955
  quote || str.empty? || str != str.strip || str =~ /[[:cntrl:]]/ ||
873
956
  str =~ /^[!*&:@%$"'|`]/ || str =~ /^-?\d+(\.\d+)?$/ || str =~ /^[<>=-]/ ||
@@ -892,17 +975,16 @@ module Gem
892
975
  end
893
976
 
894
977
  def load(str, permitted_classes: [], permitted_symbols: [], aliases: true)
895
- raise TypeError, "no implicit conversion of nil into String" if str.nil?
896
- return nil if str.empty?
897
-
898
978
  ast = Parser.new(str).parse
899
- return nil if ast.nil?
900
-
901
- Builder.new(
979
+ result = Builder.new(
902
980
  permitted_classes: permitted_classes,
903
981
  permitted_symbols: permitted_symbols,
904
982
  aliases: aliases
905
983
  ).build(ast)
984
+ # Bundler 4.0 and older call Hash methods on what this returns for
985
+ # .bundle/config, which is just "---" once its last key is unset, so
986
+ # nil stays a Hash here as it did in RubyGems 4.0.
987
+ result.nil? ? {} : result
906
988
  end
907
989
  end
908
990
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bundler
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.0.beta3
4
+ version: 4.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yehuda Katz
@@ -411,7 +411,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
411
411
  - !ruby/object:Gem::Version
412
412
  version: 3.4.1
413
413
  requirements: []
414
- rubygems_version: 4.1.0.beta3
414
+ rubygems_version: 4.1.0
415
415
  specification_version: 4
416
416
  summary: The best way to manage your application's dependencies
417
417
  test_files: []