Skip to content

Conversation

@jordansissel
Copy link
Owner

Fixes:

  • Avoid endless range, use -1 as end of range if appropriate. (introduced in ruby 2.6.0)
  • Avoid using String arg for StringScanner#scan(), use regex instead. (was introduced in ruby 2.7.0)
  • Avoid Array#filter, use Array#select instead (was introduced in ruby 2.6.0)

Fixes #2120

Ruby v2.7.0 upgraded `strscan` to v1.0.3 which allowed String argument to
the StringScanner#scan() method.

On Ruby v2.6.0 and older, fpm 1.17.0's python.rb would call `#scan("\n")`
which fails with the following:

```
`scan': wrong argument type String (expected Regexp)
```

Passing a regex solves this and works on both newer and older rubies, as
tested: v2.5.0 and v3.4.0

Citations:

https://github.com/ruby/ruby/blob/v2_7_0/NEWS?plain=1#L677-L680
> StringScanner: Upgrade to 1.0.3.

https://github.com/ruby/strscan/blob/master/NEWS.md?plain=1#L321-L322
> 1.0.2: Added support for `String` as a pattern. This improves performance.

Found while investigating #2120
Ruby v2.6.0 introduces "endless range" syntax, such as "foo"[1..] where
`1..` is the endless range.

To fix this for rubies older than 2.6.0, the older syntax can be used,
where `String#[3..]` is the same as `String#[3..-1]` as a negative value
on a range, for a String slice, is relative to the end of the string.

Citations:

https://github.com/ruby/ruby/blob/v2_6_0/NEWS?plain=1#L29-L36
> Endless ranges are introduced

Fixes #2120
Ruby 2.6.0 added Array#filter as an alias for an existing method,
Array#select.

Citations:

https://github.com/ruby/ruby/blob/v2_6_0/NEWS?plain=1#L65
> Array#filter is a new alias for Array#select

Found while investigating #2120
@jordansissel
Copy link
Owner Author

GHA test suite doesn't test Ruby 2.7, so I'm testing locally ---

on ruby 2.5.0, the full test suite result:

Finished in 1 minute 5.48 seconds (files took 0.58767 seconds to load)
384 examples, 1 failure, 9 pending

The one failure seems to be a bug or misuse of fileutils:

Failures:

  1) FPM::Util#copy_entry when given files that are symlinks should keep those files as symlinks
     Failure/Error:
       FileUtils.copy_entry(src, dst, preserve, false,
                            remove_destination)

     Errno::EOPNOTSUPP:
       Operation not supported @ apply2files - /tmp/studtmp-be49cbef4f17864f8df405f8092185960f1584380b887eb72f577c6c2536/b
     # ./lib/fpm/util.rb:376:in `copy_entry'
     # ./spec/fpm/util_spec.rb:28:in `block (6 levels) in <top (required)>'
     # ./spec/fpm/util_spec.rb:24:in `block (5 levels) in <top (required)>'
     # ./spec/fpm/util_spec.rb:18:in `block (4 levels) in <top (required)>'

On ruby 2.5.0 and Linux, calling FileUtils#copy_entry with preserve=true will fail because lchmod is not implemented, it looks like?

Testing in isolation:

% ls -ld /tmp/b
lrwxrwxrwx. 1 jls jls 6 Nov 13 23:33 /tmp/b -> /tmp/a
% ruby -rfileutils -e 'FileUtils.copy_entry("/tmp/b", "/tmp/c", true, false, true)'
Traceback (most recent call last):
        5: from -e:1:in `<main>'
        4: from /home/jls/.rbenv/versions/2.5.0/lib/ruby/2.5.0/fileutils.rb:415:in `copy_entry'
        3: from /home/jls/.rbenv/versions/2.5.0/lib/ruby/2.5.0/fileutils.rb:1396:in `wrap_traverse'
        2: from /home/jls/.rbenv/versions/2.5.0/lib/ruby/2.5.0/fileutils.rb:421:in `block in copy_entry'
        1: from /home/jls/.rbenv/versions/2.5.0/lib/ruby/2.5.0/fileutils.rb:1319:in `copy_metadata'
/home/jls/.rbenv/versions/2.5.0/lib/ruby/2.5.0/fileutils.rb:1319:in `lchmod': Operation not supported @ apply2files - /tmp/c (Errno::EOPNOTSUPP)

Same error, basically. This failure seems unrelated to this change and more about how fpm may be calling copy_entry incorrectly for symlinks? I'll ignroe it for this issue.

@jordansissel
Copy link
Owner Author

Found it -- I"ll fix it here anyway. The test suite is calling FileUtil#copy_entry with preserve=true for a symlink and this errors on Ruby 2.5.0, but not 3.4.0.

@jordansissel
Copy link
Owner Author

New test, 2.5.0: 384 examples, 0 failures, 9 pending

Passes on 3.4.0 also

@jordansissel jordansissel merged commit 78d08ef into main Nov 14, 2025
0 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

backwards compatibility: "endless range" was added in ruby 2.6 causes failures on Ruby 2.5 and older.

2 participants