From ea2fd75d10e81687334f8d29e0d3e786dbdb4a53 Mon Sep 17 00:00:00 2001 From: Canapin Date: Mon, 7 Feb 2022 16:16:46 +0100 Subject: [PATCH] DEV: Fix some regexes in phpBB3 import script (#15829) 1. bbcode hashes don't always have exactly 8 characters. 2. colors aren't always hex values, it can be a color string ("red", "blue", etc). 3. The closing tag of smileys doesn't always include a `:` character (the start of the regex was already right for this particular issue) --- script/import_scripts/phpbb3/support/smiley_processor.rb | 2 +- script/import_scripts/phpbb3/support/text_processor.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/script/import_scripts/phpbb3/support/smiley_processor.rb b/script/import_scripts/phpbb3/support/smiley_processor.rb index 36df4035bb..618f99ddd2 100644 --- a/script/import_scripts/phpbb3/support/smiley_processor.rb +++ b/script/import_scripts/phpbb3/support/smiley_processor.rb @@ -18,7 +18,7 @@ module ImportScripts::PhpBB3 def replace_smilies(text) # :) is encoded as :) - text.gsub!(/.*?/) do + text.gsub!(/.*?/) do emoji($1) end end diff --git a/script/import_scripts/phpbb3/support/text_processor.rb b/script/import_scripts/phpbb3/support/text_processor.rb index f49765d648..622f0a931c 100644 --- a/script/import_scripts/phpbb3/support/text_processor.rb +++ b/script/import_scripts/phpbb3/support/text_processor.rb @@ -78,10 +78,10 @@ module ImportScripts::PhpBB3 # Many phpbb bbcode tags have a hash attached to them. Examples: # [url=https://google.com:1qh1i7ky]click here[/url:1qh1i7ky] # [quote="cybereality":b0wtlzex]Some text.[/quote:b0wtlzex] - text.gsub!(/:(?:\w{8})\]/, ']') + text.gsub!(/:(?:\w{5,8})\]/, ']') # remove color tags - text.gsub!(/\[\/?color(=#[a-z0-9]*)?\]/i, "") + text.gsub!(/\[\/?color(=#?[a-z0-9]*)?\]/i, "") end def bbcode_to_md(text)