From d118c84b0b9110462e479487ffaf175a75e5718e Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Fri, 14 Jun 2019 17:50:31 -0700 Subject: Fix IO#scanf on pipes on Windows IO.seek on a pipe on Windows raises Errno::EINVAL instead of Errno::ESPIPE. Fixes Ruby Bug #15199 --- lib/scanf.rb | 2 +- test/scanf/test_scanfio.rb | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/scanf.rb b/lib/scanf.rb index 42fa548025..23ebbbd842 100644 --- a/lib/scanf.rb +++ b/lib/scanf.rb @@ -660,7 +660,7 @@ class IO begin seek(start_position + matched_so_far, IO::SEEK_SET) - rescue Errno::ESPIPE + rescue Errno::ESPIPE, Errno::EINVAL end soak_up_spaces if fstr.last_spec && fstr.space diff --git a/test/scanf/test_scanfio.rb b/test/scanf/test_scanfio.rb index cec8750aef..f7c439276d 100644 --- a/test/scanf/test_scanfio.rb +++ b/test/scanf/test_scanfio.rb @@ -17,5 +17,12 @@ class TestScanfIO < Test::Unit::TestCase ensure fh.close end + + def test_pipe_scanf + r, w = IO.pipe + w.write('a') + w.close + assert_equal([], r.scanf('a')) + end end -- cgit v1.2.3