Skip to content

Commit abc78fd

Browse files
committed
update
1 parent 5654dc7 commit abc78fd

File tree

5 files changed

+617
-496
lines changed

5 files changed

+617
-496
lines changed

Gemfile

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
source "http://rubygems.org"
22
gemspec
33

4-
gem "posix-spawn", :platforms => :ruby
54
gem "redcarpet", :platforms => :ruby
65
gem "kramdown", :platforms => :jruby
76
gem "RedCloth"

HISTORY.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Bump nokogiri from 1.8.1 to 1.16.5
44
* Bump nokogiri-diff from 0.2.0 to 0.3.0
55
* Bump rdoc from 3.6 to 6.7.0
6+
* Update CommandImplementation to better support large files (affecting RST and POD6 rendering)
67

78
## 4.0.2 - 2023-10-10
89
* Add support for .mdx files in markdown

lib/github/markup/command_implementation.rb

+8-28
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
begin
2-
require "posix-spawn"
3-
rescue LoadError
4-
require "open3"
5-
end
6-
1+
require "open3"
72
require "github/markup/implementation"
83

94

@@ -39,28 +34,13 @@ def call_block(rendered, content)
3934
end
4035
end
4136

42-
if defined?(POSIX::Spawn)
43-
def execute(command, target)
44-
spawn = POSIX::Spawn::Child.new(*command, :input => target)
45-
if spawn.status.success?
46-
sanitize(spawn.out, target.encoding)
47-
else
48-
raise CommandError.new(spawn.err.strip)
49-
end
50-
end
51-
else
52-
def execute(command, target)
53-
output = Open3.popen3(*command) do |stdin, stdout, stderr, wait_thr|
54-
stdin.puts target
55-
stdin.close
56-
if wait_thr.value.success?
57-
stdout.readlines
58-
else
59-
raise CommandError.new(stderr.readlines.join('').strip)
60-
end
61-
end
62-
sanitize(output.join(''), target.encoding)
63-
end
37+
def execute(command, target)
38+
# capture3 blocks until both buffers are written to and the process terminates, but
39+
# it won't allow either buffer to fill up
40+
stdout, stderr, status = Open3.capture3(*command, stdin_data: target)
41+
42+
raise CommandError.new(stderr) unless status.success?
43+
sanitize(stdout, target.encoding)
6444
end
6545

6646
def sanitize(input, encoding)

test/markup_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def test_raises_error_if_command_exits_non_zero
111111
begin
112112
GitHub::Markup.render('README.java', "stop swallowing errors", symlink: false)
113113
rescue GitHub::Markup::CommandError => e
114-
assert_equal "failure message", e.message
114+
assert_equal "failure message", e.message.strip
115115
else
116116
fail "an exception was expected but was not raised"
117117
end

0 commit comments

Comments
 (0)