FIX: Make post created/edited automation trigger regexes more specific (#32944)

- For `with_images`, ignore `<img>` tags representing emoji or a quote
avatar
- For `with_links` and `with_uploads`, exclude tags starting with the
letter "a" other than `<a>` (like `<aside>`)
- For `with_code`, the `<pre>` tag wasn't being detected because it was
expecting an extra char before the ">"
This commit is contained in:
Chris Alberti
2025-05-27 15:40:00 -05:00
committed by GitHub
parent 90ee5cfadd
commit 0b65360094
2 changed files with 36 additions and 4 deletions

View File

@ -102,11 +102,14 @@ module DiscourseAutomation
cooked = post.cooked
# note the only 100% correct way is to lean on an actual HTML parser
# however triggers may pop up during the post creation process, we can not afford a full parse
next if post_features.include?("with_images") && !cooked.match?(/<img[^>]+>/i)
next if post_features.include?("with_links") && !cooked.match?(/<a[^>]+>/i)
next if post_features.include?("with_code") && !cooked.match?(/<pre[^>]+>/i)
if post_features.include?("with_images") &&
!cooked.match?(/<img(?![^>]*class=["'](emoji|avatar))[^>]*>/i)
next
end
next if post_features.include?("with_links") && !cooked.match?(/<a\s+[^>]*>/i)
next if post_features.include?("with_code") && !cooked.match?(/<pre[^>]*>/i)
if post_features.include?("with_uploads") &&
!cooked.match?(/<a[^>]+class=["']attachment[^>]+>/i)
!cooked.match?(/<a\s+[^>]*class=["']attachment[^>]*>/i)
next
end
end