Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update CommandImplementation to handle large stdout #1808

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 4.0.3 - 2024-06-06
* Update CommandImplementation to better support large files (affecting RST and POD6 rendering)

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

Expand Down
2 changes: 1 addition & 1 deletion lib/github-markup.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module GitHub
module Markup
VERSION = '4.0.2'
VERSION = '4.0.3'
Version = VERSION
end
end
16 changes: 6 additions & 10 deletions lib/github/markup/command_implementation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +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
if wait_thr.value.success?
stdout.readlines
else
raise CommandError.new(stderr.readlines.join('').strip)
end
end
sanitize(output.join(''), target.encoding)
# 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)

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
Loading