Skip to content
代码片段 群组 项目
提交 bd432cbb 编辑于 作者: Rodrigo Tomonari's avatar Rodrigo Tomonari
浏览文件

Fix markdown import attachments in GitHub Import

Skill attachments with blank URL

Changelog: fixed
上级 052c04ee
No related branches found
No related tags found
无相关合并请求
...@@ -28,6 +28,7 @@ def from_markdown(markdown_node) ...@@ -28,6 +28,7 @@ def from_markdown(markdown_node)
def from_markdown_image(markdown_node) def from_markdown_image(markdown_node)
url = markdown_node.url url = markdown_node.url
return unless url
return unless github_url?(url, media: true) return unless github_url?(url, media: true)
return unless whitelisted_type?(url, media: true) return unless whitelisted_type?(url, media: true)
...@@ -37,6 +38,7 @@ def from_markdown_image(markdown_node) ...@@ -37,6 +38,7 @@ def from_markdown_image(markdown_node)
def from_markdown_link(markdown_node) def from_markdown_link(markdown_node)
url = markdown_node.url url = markdown_node.url
return unless url
return unless github_url?(url, docs: true) return unless github_url?(url, docs: true)
return unless whitelisted_type?(url, docs: true) return unless whitelisted_type?(url, docs: true)
...@@ -46,7 +48,7 @@ def from_markdown_link(markdown_node) ...@@ -46,7 +48,7 @@ def from_markdown_link(markdown_node)
def from_inline_html(markdown_node) def from_inline_html(markdown_node)
img = Nokogiri::HTML.parse(markdown_node.string_content).xpath('//img')[0] img = Nokogiri::HTML.parse(markdown_node.string_content).xpath('//img')[0]
return unless img return if img.nil? || img[:src].blank?
return unless github_url?(img[:src], media: true) return unless github_url?(img[:src], media: true)
return unless whitelisted_type?(img[:src], media: true) return unless whitelisted_type?(img[:src], media: true)
......
...@@ -35,6 +35,12 @@ ...@@ -35,6 +35,12 @@
it { expect(described_class.from_markdown(markdown_node)).to eq nil } it { expect(described_class.from_markdown(markdown_node)).to eq nil }
end end
context 'when URL is blank' do
let(:url) { nil }
it { expect(described_class.from_markdown(markdown_node)).to eq nil }
end
end end
context "when it's an image attachment" do context "when it's an image attachment" do
...@@ -63,6 +69,12 @@ ...@@ -63,6 +69,12 @@
it { expect(described_class.from_markdown(markdown_node)).to eq nil } it { expect(described_class.from_markdown(markdown_node)).to eq nil }
end end
context 'when URL is blank' do
let(:url) { nil }
it { expect(described_class.from_markdown(markdown_node)).to eq nil }
end
end end
context "when it's an inline html node" do context "when it's an inline html node" do
...@@ -80,6 +92,12 @@ ...@@ -80,6 +92,12 @@
expect(attachment.name).to eq name expect(attachment.name).to eq name
expect(attachment.url).to eq url expect(attachment.url).to eq url
end end
context 'when image src is not present' do
let(:img) { "<img width=\"248\" alt=\"#{name}\">" }
it { expect(described_class.from_markdown(markdown_node)).to eq nil }
end
end end
end end
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册