Skip to content

Commit

Permalink
Moving to capture3 for implementation and adding a test ensuring that…
Browse files Browse the repository at this point in the history
… large RST files are processed
  • Loading branch information
TylerDixon committed Jun 5, 2024
1 parent f0ffbd7 commit 5dabbff
Show file tree
Hide file tree
Showing 3 changed files with 3,005 additions and 11 deletions.
16 changes: 5 additions & 11 deletions lib/github/markup/command_implementation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,12 @@ def execute(command, target)
end
else
def execute(command, target)
output = Open3.popen3(*command) do |stdin, stdout, stderr, wait_thr|
stdin.puts target
stdin.close
# capture3 blocks until both buffers are written to and the process terminates, but
# it won't allow either buffer to fill up
stdout, stderr, status = Open3.capture3(*command, stdin_data: target)

stdout_lines = stdout.readlines
stderr_lines = stderr.readlines.join('').strip

raise CommandError.new(stderr_lines) unless wait_thr.value.success?

stdout_lines
end
sanitize(output.join(''), target.encoding)
raise CommandError.new(stderr) unless status.success?
sanitize(stdout, target.encoding)
end
end

Expand Down
4 changes: 4 additions & 0 deletions test/markup_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,8 @@ def test_commonmarker_options
assert_equal "&lt;style>.red{color: red;}&lt;/style>\n", GitHub::Markup.render_s(GitHub::Markups::MARKUP_MARKDOWN, "<style>.red{color: red;}</style>", options: {commonmarker_opts: [:UNSAFE]})
assert_equal "<style>.red{color: red;}</style>\n", GitHub::Markup.render_s(GitHub::Markups::MARKUP_MARKDOWN, "<style>.red{color: red;}</style>", options: {commonmarker_opts: [:UNSAFE], commonmarker_exts: [:autolink, :table, :strikethrough]})
end

def test_large_document_with_command_implementation
assert GitHub::Markup.render_s(:rst, File.read("test/markups/README_large.rst"))
end
end
Loading

0 comments on commit 5dabbff

Please sign in to comment.