Censor specific text patterns


(Chris D) #1

Hi, I saw in Discourse that there is a way to censor words in admin/site_settings/category/posting - does anyone know of a way to censor specific patterns? For example, I foresee HR people eventually using the Discourse forum and to protect them from themselves posting sensitive info I want to automatically remove SSNs (i.e. XXX-XX-XXXX). Has anyone had this need before and found a way to do it?

Please share any advice :smile:

Cheers,
Chris


(Jeff Atwood) #2

We don’t support censoring wildcards or regular expressions, would probably need to be a plugin.


(Michael Downey) #3

Something like this would also be useful for the inclusion of full email addresses being discussed in other topics right now and caused by HTML email parsing bugs.


(Jeff Atwood) #4

This would absolutely require the work that @zogstrip is doing around hoisting out code and pre blocks in the pipeline earlier.


(Chris D) #5

Thanks Jeff. If @zogstrip needs help testing at any point I would be happy to help :smile:.


(Régis Hanol) #6

How is it related to the hoisting of code blocks?


(Chris D) #7

Honestly, not sure…just asked about censoring text patterns. Jeff mentioned you were working on something related, maybe he can clarify :slight_smile:?


(Jeff Atwood) #8

The regex to block, say, a phone number pattern, would match inside pre and code blocks unless they were hoisted out very early in the pipeline.


(Régis Hanol) #9

Ok, so now that it’s done, @optimus, you’ll need to write a plugin :wink:

Something like (not tested)

Discourse.Dialect.addPreProcessor(function(text) {
   return text.replace(/your-regexp/g, "your replacement");
}); 

(Jeff Atwood) #10

This now exists, see


(Jeff Atwood) #11