FIX: BBcode edge case for `InlineUploads`.

FIX: BBcode edge case for InlineUploads.

diff --git a/app/services/inline_uploads.rb b/app/services/inline_uploads.rb
index 816e848..4ae95e8 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 e563eee..ef7f48d 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

GitHub sha: 53efb7bd

2 Likes