Skip to content

Commit 23c0266

Browse files
wkjagtjonleighton
authored andcommitted
Use Bundler::LockfileParser to parse lockfile instead of regex (rails#492)
The regex that was used to parse the lockfile was not working in the case where git is configured with `core.autocrlf true`. This changes the line endings in the lockfile to \r\n, causing the dollar signs in the pattern to not match. This changes the parsing of the lockfile to use Bundler::LockfileParser
1 parent 5d8eb0e commit 23c0266

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

Diff for: lib/spring/client/binstub.rb

+3-6
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ class Binstub < Command
2323
# binstub from the application process. Which means that in the application
2424
# process we'll execute the lines which come after the LOADER block, which
2525
# is what we want.
26-
#
27-
# Parsing the lockfile in this way is pretty nasty but reliable enough
28-
# The regex ensures that the match must be between a GEM line and an empty
29-
# line, so it won't go on to the next section.
3026
SPRING = <<'CODE'
3127
#!/usr/bin/env ruby
3228
@@ -37,9 +33,10 @@ class Binstub < Command
3733
require 'rubygems'
3834
require 'bundler'
3935
40-
if (match = Bundler.default_lockfile.read.match(/^GEM$.*?^ (?: )*spring \((.*?)\)$.*?^$/m))
36+
lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read)
37+
if spring = lockfile.specs.detect { |spec| spec.name == "spring" }
4138
Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path
42-
gem 'spring', match[1]
39+
gem 'spring', spring.version
4340
require 'spring/binstub'
4441
end
4542
end

0 commit comments

Comments
 (0)