From 5521aac4abfcdae755953905cb1aca0eaae8d713 Mon Sep 17 00:00:00 2001 From: Claire Date: Mon, 16 Mar 2026 10:39:18 +0100 Subject: [PATCH] Fix hashtags preceded by non-break spaces not being processed as such (#38212) --- app/models/tag.rb | 2 +- spec/models/tag_spec.rb | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/models/tag.rb b/app/models/tag.rb index 224ec32736..b14dfce763 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -41,7 +41,7 @@ class Tag < ApplicationRecord HASHTAG_LAST_SEQUENCE = '([[:word:]_]*[[:alpha:]][[:word:]_]*)' HASHTAG_NAME_PAT = "#{HASHTAG_FIRST_SEQUENCE}|#{HASHTAG_LAST_SEQUENCE}".freeze - HASHTAG_RE = /(?<=^|\s)[##](#{HASHTAG_NAME_PAT})/ + HASHTAG_RE = /(?<=^|[[:space:]])[##](#{HASHTAG_NAME_PAT})/ HASHTAG_NAME_RE = /\A(#{HASHTAG_NAME_PAT})\z/i HASHTAG_INVALID_CHARS_RE = /[^[:alnum:]\u0E47-\u0E4E#{HASHTAG_SEPARATORS}]/ diff --git a/spec/models/tag_spec.rb b/spec/models/tag_spec.rb index 9fe723b3ba..61ef531fe1 100644 --- a/spec/models/tag_spec.rb +++ b/spec/models/tag_spec.rb @@ -103,6 +103,10 @@ RSpec.describe Tag do expect(subject.match('https://en.wikipedia.org/wiki/Google_LLC_v._Oracle_America,_Inc.#Decision')).to be_nil end + it 'matches a hashtag preceded by a non-break space' do + expect(subject.match('test #foo').to_s).to eq '#foo' + end + it 'matches #aesthetic' do expect(subject.match('this is #aesthetic').to_s).to eq '#aesthetic' end