mirror of
https://github.com/discourse/discourse.git
synced 2025-06-12 22:14:59 +08:00
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:
@ -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
|
||||
|
Reference in New Issue
Block a user