Skip to content

Commit 6c3e1dc

Browse files
otegamikou
andauthored
markup_parser: skip parsing HTML content when it is empty (#161)
## Issue This PR resolves the following CI error. ``` Error: FullTextSearch::BatchRunnerSynchronizeTest#test_archived_changeset: RuntimeError: input string cannot be empty plugins/full_text_search/lib/full_text_search/markup_parser.rb:20:in `parse' plugins/full_text_search/lib/full_text_search/issue_mapper.rb:25:in `upsert_fts_target' plugins/full_text_search/lib/full_text_search/batch_runner.rb:129:in `block (2 levels) in synchronize_fts_targets_internal' plugins/full_text_search/lib/full_text_search/batch_runner.rb:335:in `each' plugins/full_text_search/lib/full_text_search/batch_runner.rb:335:in `each' plugins/full_text_search/lib/full_text_search/batch_runner.rb:335:in `iterate' plugins/full_text_search/lib/full_text_search/batch_runner.rb:121:in `block in synchronize_fts_targets_internal' plugins/full_text_search/lib/full_text_search/resolver.rb:43:in `each' plugins/full_text_search/lib/full_text_search/resolver.rb:43:in `each' plugins/full_text_search/lib/full_text_search/batch_runner.rb:116:in `synchronize_fts_targets_internal' plugins/full_text_search/lib/full_text_search/batch_runner.rb:12:in `synchronize' plugins/full_text_search/test/unit/full_text_search/batch_runner_synchronize_test.rb:34:in `setup' bin/rails test plugins/full_text_search/test/unit/full_text_search/batch_runner_synchronize_test.rb:219 ``` ## Cause The error occurs because Nokogiri's behavior for handling an empty string changed in version 1.17.0. - Before 1.17.0: `Nokogiri::HTML::SAX::Parser#parse` returned `nil` when passed an empty string. - After 1.17.0: `Nokogiri::HTML::SAX::Parser#parse` raises a `RuntimeError` when passed an empty string. Refer to the following Nokogiri commit for details: sparklemotion/nokogiri@35596e7 ## Solution Skip parsing the HTML content when it is empty by adding a presence check. --------- Co-authored-by: Sutou Kouhei <[email protected]>
1 parent d1b063d commit 6c3e1dc

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

lib/full_text_search/markup_parser.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ def parse(object, attribute, options={})
1515
html = with_user(User.admin.first) do
1616
textilizable(object, attribute, options)
1717
end
18+
return ["", []] unless html.present?
19+
1820
document = Document.new
1921
parser = Nokogiri::HTML::SAX::Parser.new(document)
2022
parser.parse(html)

0 commit comments

Comments
 (0)