From 53efb7bd24cc94083f48a8b001237bcb51cc4409 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Thu, 20 Jun 2019 11:47:32 +0800 Subject: [PATCH] FIX: BBcode edge case for `InlineUploads`. --- app/services/inline_uploads.rb | 2 +- spec/services/inline_uploads_spec.rb | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/services/inline_uploads.rb b/app/services/inline_uploads.rb index 816e848f7d1..4ae95e8ce56 100644 --- a/app/services/inline_uploads.rb +++ b/app/services/inline_uploads.rb @@ -177,7 +177,7 @@ class InlineUploads end def self.match_bbcode_img(markdown, external_src: false) - markdown.scan(/(\[img\]\s?(.+)\s?\[\/img\])/) do |match| + markdown.scan(/(\[img\]\s*([^\[\]\s]+)\s*\[\/img\])/) do |match| if (matched_uploads(match[1]).present? && block_given?) || external_src yield(match[0], match[1], +"![](#{PLACEHOLDER})", $~.offset(0)[0]) end diff --git a/spec/services/inline_uploads_spec.rb b/spec/services/inline_uploads_spec.rb index e563eee1435..ef7f48d7c73 100644 --- a/spec/services/inline_uploads_spec.rb +++ b/spec/services/inline_uploads_spec.rb @@ -163,6 +163,8 @@ RSpec.describe InlineUploads do [img] #{upload2.url} [/img] + + [img]#{upload.url}[/img][img]#{upload2.url}[/img] MD expect(InlineUploads.process(md)).to eq(<<~MD) @@ -171,6 +173,8 @@ RSpec.describe InlineUploads do ![](#{upload3.short_url}) ![](#{upload2.short_url}) + + ![](#{upload.short_url})![](#{upload2.short_url}) MD end