From 1fde7e387495e871fb5537dd191dc076fb838a94 Mon Sep 17 00:00:00 2001 From: saint Date: Mon, 9 Sep 2024 13:05:00 +1000 Subject: [PATCH] 0.52 Refine regex for extra case --- plugin.rb | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/plugin.rb b/plugin.rb index 8657119..1f658f8 100644 --- a/plugin.rb +++ b/plugin.rb @@ -4,7 +4,7 @@ # name: discourse-legacy_links # about: A plugin to handle legacy Gossamer Forums URLs -# version: 0.51 +# version: 0.52 # authors: saint@federated.computer # url: https://gitea.federated.computer/saint/discourse-legacy_links.git @@ -67,11 +67,17 @@ after_initialize do # request.path.match(%r{/forum/.*_P(\d+)(?:/|$)})&. || # Matches URLs like /forum/.../P6751045/ or /forum/.../P6751045 # request.query_string.match(/post=(\d+)/)&. || # Matches URLs with ?post= in query string # request.query_string.match(/parent_post_id=(\d+)/)&. # Matches URLs with ?parent_post_id= in query string +# post_id = params[:post_id].presence || +# request.path.match(%r{/P(\d+)(?:/|$)})&.[](1) || # Matches URLs like /P40796/ or /P40796 (no trailing slash) +# request.path.match(%r{/forum/.*_P(\d+)(?:/|$)})&.[](1) || # Matches URLs like /forum/.../P6751045/ or /forum/.../P6751045 +# request.query_string.match(/post=(\d+)/)&.[](1) || # Matches URLs with ?post= in query string +# request.query_string.match(/parent_post_id=(\d+)/)&.[](1) # Matches URLs with ?parent_post_id= in query string post_id = params[:post_id].presence || - request.path.match(%r{/P(\d+)(?:/|$)})&.[](1) || # Matches URLs like /P40796/ or /P40796 (no trailing slash) - request.path.match(%r{/forum/.*_P(\d+)(?:/|$)})&.[](1) || # Matches URLs like /forum/.../P6751045/ or /forum/.../P6751045 - request.query_string.match(/post=(\d+)/)&.[](1) || # Matches URLs with ?post= in query string - request.query_string.match(/parent_post_id=(\d+)/)&.[](1) # Matches URLs with ?parent_post_id= in query string + request.path.match(%r{/P(\d+)(?:-\d+)?(?:/|$)})&.[](1) || # Matches URLs like /P40796/, /P40796, or /P40796-5/ + request.path.match(%r{/forum/.*_P(\d+)(?:-\d+)?(?:/|$)})&.[](1) || # Matches URLs like /forum/.../P6751045/, /forum/.../P6751045, or /forum/.../P6751045-5/ + request.query_string.match(/post=(\d+)/)&.[](1) || # Matches URLs with ?post= in query string + request.query_string.match(/parent_post_id=(\d+)/)&.[](1) # Matches URLs with ?parent_post_id= in query string + Rails.logger.info("DiscourseLegacyLinks: Extracted raw post_id: #{post_id || 'nil'}") post_id.to_i if post_id