# \* wildcards in Watched Words (Censor) don't work

**URL:** https://meta.discourse.org/t/wildcards-in-watched-words-censor-dont-work/77007
**Category:** Feature
**Created:** [31.Декабрь.2017 06:37:30 UTC](https://meta.discourse.org/t/wildcards-in-watched-words-censor-dont-work/77007 "2017-12-31T06:37:30Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![schungx](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/schungx/32/70989_2.png) [@schungx](https://meta.discourse.org/u/schungx)
#### Post date: [31.Декабрь.2017 06:37:31 UTC](https://meta.discourse.org/t/wildcards-in-watched-words-censor-dont-work/77007/1 "2017-12-31T06:37:31Z")

</div>

Repo:

1. Make sure Site Settings \> watched words regular expressions is OFF
2. Go to Logs \> Watched Words
3. Type in `somebadword*` in `Censor`
4. `./launcher restart app` (this step appears to be necessary when the watched words list is changed, although I can’t understand why)
5. Try to type in `somebadword` in the compose window. No effect.
6. Check `admin/watch_words.json` and confirm that the word is accurately entered as `somebadword*`

> <https://github.com/discourse/discourse/blob/37854299488e47a7eac818e577c65e9431501b46/app/services/word_watcher.rb#L28-L35>

This code should be replacing `*` with `\S*` (but I’m not sure if it will get lower-cased in the end). Somehow it is not matching.

---

<div class="post-metadata">

### Author: ![schungx](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/schungx/32/70989_2.png) [@schungx](https://meta.discourse.org/u/schungx)
#### Post date: [31.Декабрь.2017 06:39:13 UTC](https://meta.discourse.org/t/wildcards-in-watched-words-censor-dont-work/77007/2 "2017-12-31T06:39:13Z")

</div>

Incidentally:

1. Site Settings \> watched words regular expressions is ON
2. Go to Logs \> Watched Words
3. Type in `somebadword\w*` in `Censor`
4. Confirm that `admin/watched_words.json` comes back with the correct `somebadword\w*`
5. Try in compose window, no effect.

EDIT: It is `Censor` that is not working.

---

<div class="post-metadata">

### Author: ![neil](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/neil/32/102150_2.png) [@neil](https://meta.discourse.org/u/neil)
#### Post date: [03.Январь.2018 20:08:30 UTC](https://meta.discourse.org/t/wildcards-in-watched-words-censor-dont-work/77007/3 "2018-01-03T20:08:30Z")

</div>

Works on my machine…

 ![30 PM](https://global.discourse-cdn.com/meta/original/3X/3/a/3aaf7f9867fc7e6026acfc3caff4d18cd69df1ce.png)

 ![38 PM](https://global.discourse-cdn.com/meta/original/3X/8/e/8e52a67bd4720bc2ab95c482d478905e8bb67e95.png)

> [@schungx](#):
>
> ./launcher restart app (this step appears to be necessary when the watched words list is changed, although I can’t understand why)

It’s not necessary.

> [@schungx](#):
>
> Try to type in somebadword in the compose window. No effect.

Are you doing this as a moderator or admin? If so, that explains why you aren’t seeing anything.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [03.Январь.2018 22:53:46 UTC](https://meta.discourse.org/t/wildcards-in-watched-words-censor-dont-work/77007/4 "2018-01-03T22:53:46Z")

</div>

Yes staff are immune to this by design. So not a bug.

---

<div class="post-metadata">

### Author: ![schungx](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/schungx/32/70989_2.png) [@schungx](https://meta.discourse.org/u/schungx)
#### Post date: [04.Январь.2018 03:21:53 UTC](https://meta.discourse.org/t/wildcards-in-watched-words-censor-dont-work/77007/5 "2018-01-04T03:21:53Z")

</div>

Nope. Already tried it with a normal account. Everything that is wild-carded won’t get masked out.

Incidentally, if a word is included in `censored pattern` (note: this is in Settings, not in Watched Words), then it gets masked even when I’m admin. But this is beyond this question.

I’m running v1.9.0.beta17 +78. Should I be trying with the latest?

---

<div class="post-metadata">

### Author: ![schungx](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/schungx/32/70989_2.png) [@schungx](https://meta.discourse.org/u/schungx)
#### Post date: [04.Январь.2018 03:31:00 UTC](https://meta.discourse.org/t/wildcards-in-watched-words-censor-dont-work/77007/6 "2018-01-04T03:31:00Z")

</div>

Site setup:

![image](https://global.discourse-cdn.com/meta/original/3X/2/7/273a4800c411fb99af960c370c971e16743a5063.png)

Normal user:

 ![image](https://global.discourse-cdn.com/meta/original/3X/b/3/b3bcf82bbff3676ad0233a78bc1a64d4baa9fb42.png)

This site is running Beta15. I’ll upgrade to latest and report back.

EDIT: Sorry for not being clear, it is `Censor` that is not working for me. Not `Block` or `Flag` (haven’t tried those).

EDIT 2: OK, Upgraded to latest. Checked. `Block` and `Flag` both work fine. Only `Censor` is not working. I’ve updated the topic title.

---

<div class="post-metadata">

### Author: ![thethirdpudding](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/thethirdpudding/32/86901_2.png) [@thethirdpudding](https://meta.discourse.org/u/thethirdpudding)
#### Post date: [08.Январь.2018 23:49:53 UTC](https://meta.discourse.org/t/wildcards-in-watched-words-censor-dont-work/77007/7 "2018-01-08T23:49:53Z")

</div>

Hello!

I’m also having trouble using the Watched Words to prevent my community from not respecting TOS over topics and private messages.

Like @schungx, `censored pattern` from Site Settings is working great, but I’d rather use Watched Words with `Required Approval` to prevent users from trying to sneak around the regex I’m using.

However, I was only able to trigger the flagging system when creating topics and writing replies. Private messages just won’t trigger anything (Approval, Censor, Flag or Block).  
This was tested on v2.0.0.beta1 +26 with 2 test accounts.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [09.Январь.2018 02:14:05 UTC](https://meta.discourse.org/t/wildcards-in-watched-words-censor-dont-work/77007/8 "2018-01-09T02:14:05Z")

</div>

Can you repro this @neil?

---

<div class="post-metadata">

### Author: ![neil](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/neil/32/102150_2.png) [@neil](https://meta.discourse.org/u/neil)
#### Post date: [09.Январь.2018 16:51:21 UTC](https://meta.discourse.org/t/wildcards-in-watched-words-censor-dont-work/77007/9 "2018-01-09T16:51:21Z")

</div>

I can only confirm that censoring a word like `somebadword*` doesn’t work.

> [@thethirdpudding](#):
>
> Private messages just won’t trigger anything (Approval, Censor, Flag or Block).

Off topic, but word watching works in pm’s for me.

 ![11 AM](https://global.discourse-cdn.com/meta/original/3X/9/f/9feb6e0d8c9adc571870b2176db41da85e5d5950.png)

@thethirdpudding Please open a new topic in #Support to explain what you’re doing.

---

<div class="post-metadata">

### Author: ![neil](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/neil/32/102150_2.png) [@neil](https://meta.discourse.org/u/neil)
#### Post date: [09.Январь.2018 22:17:21 UTC](https://meta.discourse.org/t/wildcards-in-watched-words-censor-dont-work/77007/11 "2018-01-09T22:17:21Z")

</div>

I fixed this today. Wildcards should work in censored words now.

---

<div class="post-metadata">

### Author: ![schungx](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/schungx/32/70989_2.png) [@schungx](https://meta.discourse.org/u/schungx)
#### Post date: [10.Январь.2018 04:04:10 UTC](https://meta.discourse.org/t/wildcards-in-watched-words-censor-dont-work/77007/12 "2018-01-10T04:04:10Z")

</div>

I’m sorry, but not so fast.

Watched Words Censor now works for words with wildcards.

However, it _doesn’t_ work if `watched_words_regular_expression` is true.

I don’t think the censor function even considers it as regular expression at all.

Repo:

1. Settings \> watched words regular expression ==\> ON
2. Add `xyz*` to `Censor`
3. In compose window, type `xyz123`
4. See that it is censored as it is treating the `*` as a wildcard. If it is treated as a regular expression, `xyz*` should only match `xy` followed by a string of `zzzz`…

EDIT: The below is the culprit…

> <https://github.com/discourse/discourse/blob/ad62f1099cdb8782d20ca1296ea73467bc35fce7/app/assets/javascripts/pretty-text/censored-words.js.es6#L11-L13>

Notice that it is not even considering that the pattern may already be a regular expression.

Also,

> <https://github.com/discourse/discourse/blob/ad62f1099cdb8782d20ca1296ea73467bc35fce7/app/assets/javascripts/pretty-text/censored-words.js.es6#L23>

This is always assuming that the pattern is a word pattern and `\b` pairs are auto-wrapped onto it. If the pattern is a regular expression, obviously the `\b` pairs can be omitted because the user should put them in himself.

---

<div class="post-metadata">

### Author: ![Tom\_Newsom](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tom_newsom/32/115981_2.png) [@Tom\_Newsom](https://meta.discourse.org/u/Tom_Newsom)
#### Post date: [10.Январь.2018 09:31:20 UTC](https://meta.discourse.org/t/wildcards-in-watched-words-censor-dont-work/77007/13 "2018-01-10T09:31:20Z")

</div>

Wildcards in censor lists can be problematic…

 ![image](https://global.discourse-cdn.com/meta/original/3X/a/c/ace2a38b73a7dff313fe9519296ce541fc71e74c.jpg)

 ![image](https://global.discourse-cdn.com/meta/original/3X/5/2/527b229d5a2a61375fbf50ec8cb7f5ae7d66be26.jpg)

---

<div class="post-metadata">

### Author: ![schungx](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/schungx/32/70989_2.png) [@schungx](https://meta.discourse.org/u/schungx)
#### Post date: [10.Январь.2018 10:55:31 UTC](https://meta.discourse.org/t/wildcards-in-watched-words-censor-dont-work/77007/14 "2018-01-10T10:55:31Z")

</div>

Well, if you put in `*shit*` then obviously that is what you’ll get… Since you are explicitly asking the system to filter out anything containing these words.

Usually you’ll be using `shit*` for example…

But of course, it won’t be 100% fool-proof if you use any wildcard. For example:

`I love shitaki mushrooms!`

---

<div class="post-metadata">

### Author: ![neil](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/neil/32/102150_2.png) [@neil](https://meta.discourse.org/u/neil)
#### Post date: [10.Январь.2018 15:51:11 UTC](https://meta.discourse.org/t/wildcards-in-watched-words-censor-dont-work/77007/15 "2018-01-10T15:51:11Z")

</div>

> [@schungx](#):
>
> This is always assuming that the pattern is a word pattern and \b pairs are auto-wrapped onto it. If the pattern is a regular expression, obviously the \b pairs can be omitted because the user should put them in himself.

@eviltrout is this setting meant to force every word to explicitly include the word boundaries in the patterns? This feature was added for a specific customer, so removing the `\b` around the patterns could have… surprising consequences!

> [@schungx](#):
>
> See that it is censored as it is treating the \* as a wildcard. If it is treated as a regular expression, xyz\* should only match xy followed by a string of zzzz…

Agreed. Censor wasn’t updated to support `watched_words_regular_expression`, so I’ll need to implement it.

---

<div class="post-metadata">

### Author: ![eviltrout](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eviltrout/32/5275_2.png) [@eviltrout](https://meta.discourse.org/u/eviltrout)
#### Post date: [10.Январь.2018 16:03:04 UTC](https://meta.discourse.org/t/wildcards-in-watched-words-censor-dont-work/77007/16 "2018-01-10T16:03:04Z")

</div>

> [@neil](#):
>
> This feature was added for a specific customer, so removing the \b around the patterns could have… surprising consequences!

Yes this was intentional. If you write the regular expression yourself you can control whether it’s on a boundary or not. Some of the watched words we imported were not for example! It’s a power feature.

---

<div class="post-metadata">

### Author: ![neil](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/neil/32/102150_2.png) [@neil](https://meta.discourse.org/u/neil)
#### Post date: [10.Январь.2018 19:24:08 UTC](https://meta.discourse.org/t/wildcards-in-watched-words-censor-dont-work/77007/17 "2018-01-10T19:24:08Z")

</div>

@schungx It should work now. Plz update and try again.

---

<div class="post-metadata">

### Author: ![schungx](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/schungx/32/70989_2.png) [@schungx](https://meta.discourse.org/u/schungx)
#### Post date: [11.Январь.2018 04:40:15 UTC](https://meta.discourse.org/t/wildcards-in-watched-words-censor-dont-work/77007/18 "2018-01-11T04:40:15Z")

</div>

Yup. It makes sense to wrap with `\b` for regular mode since it is simpler and makes sense (at least for English). A small pitfall is that it screws up on non-ASCII letters, but that’s a small issue comparatively speaking.

When a site turns on _regular expression_, you assume that the admin knows what he/she is doing and write correct regexp’s. Then those `\b` will be an unnecessary limitation.

---

<div class="post-metadata">

### Author: ![Mittineague](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mittineague/32/114259_2.png) [@Mittineague](https://meta.discourse.org/u/Mittineague)
#### Post date: [11.Январь.2018 05:01:40 UTC](https://meta.discourse.org/t/wildcards-in-watched-words-censor-dont-work/77007/19 "2018-01-11T05:01:40Z")

</div>

I’m thinking it might be better to not deal with POSIX regex at all and limit it to PostgresSQL wildcards (\_ %)

IMHO, assuming that an Admin that _wants_ regex will _know_ regex will in most cases be quite a leap. Even devs that have advanced programming skills in general can have problems getting regex right.

---

<div class="post-metadata">

### Author: ![schungx](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/schungx/32/70989_2.png) [@schungx](https://meta.discourse.org/u/schungx)
#### Post date: [11.Январь.2018 05:04:53 UTC](https://meta.discourse.org/t/wildcards-in-watched-words-censor-dont-work/77007/20 "2018-01-11T05:04:53Z")

</div>

Not quite.

First of all, I believe the markdown processing in Discourse is actually done via JavaScript so it is natural to use JS regex.

Secondly, there are tons of online tools to check regex’s.

Thirdly, common regex’s are not difficult. The difficult ones are trying to make regex do what it wasn’t meant to do. Most of the normal scenarios are actually quite simple.

---

<div class="post-metadata">

### Author: ![schungx](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/schungx/32/70989_2.png) [@schungx](https://meta.discourse.org/u/schungx)
#### Post date: [11.Январь.2018 05:38:08 UTC](https://meta.discourse.org/t/wildcards-in-watched-words-censor-dont-work/77007/21 "2018-01-11T05:38:08Z")

</div>

Prelim testing shows that it is working perfectly fine! Good job!

Now finally I can censor Chinese! 🎉

[Следующая страница](https://meta.discourse.org/t/wildcards-in-watched-words-censor-dont-work/77007.md?page=2)
