Fix newlines being chomped in RSS import (#10476)

The CustomText converter was monkey patched to fix a bug related to
preserve_tags. Somewhere in that process, remove_inner_newlines was
changed to strip newlines completely, instead of replacing them with a
single space. This restores that functionality.

In development mode, files are not eager loaded. That means that the
converters were not being required, so it was not possible to reproduce
that issue in development mode (since it was falling back to the
original converter, which does not have the bug). This commit also adds
an initializer that requires every converter.
This commit is contained in:
Hugo Peixoto 2020-09-29 15:38:36 +01:00 committed by GitHub
parent fe75dcde1c
commit 24e9f81f5a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 1 deletions

View file

@ -40,7 +40,7 @@ module ReverseMarkdown
end
def remove_inner_newlines(text)
text.tr("\n\t", "")
text.tr("\r\n\t", " ").squeeze(" ")
end
def preserve_keychars_within_backticks(text)

View file

@ -0,0 +1,3 @@
Dir.glob(Rails.root.join("app/lib/reverse_markdown/converters/*.rb")).sort.each do |filename|
require_dependency filename
end

View file

@ -0,0 +1,16 @@
require "rails_helper"
RSpec.describe ReverseMarkdown::Converters::CustomText, type: :lib do
def create_custom_text
ReverseMarkdown.config.github_flavored = true
described_class.new
end
describe "#convert" do
it "keeps some blankspace between lines in the same paragraph" do
node = Nokogiri::HTML("newlines\nbecome\nspaces")
result = create_custom_text.convert(node)
expect(result).to eq("newlines become spaces")
end
end
end