# 테스트 감시 단어 기능이 작동하지 않습니다

**URL:** <https://meta.discourse.org/t/test-watched-words-is-broken/267026>\
**Category:** Bug\
**Tags:** watched-words\
**Created:** [6월 2, 2023, 3:11오후 UTC](https://meta.discourse.org/t/test-watched-words-is-broken/267026 "2023-06-02T15:11:48Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![Arthri](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arthri/32/211355_2.png) [@Arthri](https://meta.discourse.org/u/Arthri)\
**Post date:** [6월 2, 2023, 3:11오후 UTC](https://meta.discourse.org/t/test-watched-words-is-broken/267026/1 "2023-06-02T15:11:49Z")

</div>

감시 단어 설정 화면에서 “test” 기능을 사용할 때, “raw bracket is not allowed in regular expression with unicode flag” 오류가 콘솔에 반복적으로 출력됩니다.

1. [https://meta.discourse.org/admin/customize/watched\_words/action/require\_approval](https://meta.discourse.org/admin/customize/watched_words/action/require_approval) 로 이동합니다.
2. 브라우저 콘솔을 엽니다.
3. “Test” 버튼을 누릅니다.
4. 아무 내용이나 입력합니다.
5. 오류를 확인합니다.

해당 오류는 [watched-words.js](https://github.com/discourse/discourse/blob/56ee46bf634c5feb7403ace99513b23ac35c1597/app/assets/javascripts/discourse-common/addon/utils/watched-words.js#L3)에서 발생하며, 이는 전달되는 정규식 `(?:[^[:word:]]|^)(word1|word2)(?=[^[:word:]]|$)`이 Ruby에서는 유효하지만 JavaScript에서는 유효하지 않기 때문입니다. 이 정규식은 API인 [https://meta.discourse.org/admin/customize/watched\_words.json](https://meta.discourse.org/admin/customize/watched_words.json) 에서 가져오며, 해당 API는 [watched words serializer](https://github.com/discourse/discourse/blob/56ee46bf634c5feb7403ace99513b23ac35c1597/app/serializers/watched_word_list_serializer.rb#L21)에서 JSON을 제공합니다. 이 시리얼라이저는 `action`만 전달하여 [word watcher](https://github.com/discourse/discourse/blob/56ee46bf634c5feb7403ace99513b23ac35c1597/app/services/word_watcher.rb#L56)를 호출합니다.

몇 주 전이라면 문제가 없었을 것이지만, 특정 PR을 통해 두 개의 추가 매개변수가 도입되었습니다. 이 매개변수 중 하나는 `engine`이며, 기본값이 Ruby인 매개변수입니다. 앞서 언급한 호출에서는 이 매개변수가 지정되지 않았습니다. 따라서 반환되는 정규식은 Ruby 전용이지만, JavaScript 정규식 엔진에 의해 사용되고 있습니다.

> <https://github.com/discourse/discourse/pull/21344>
>
> Watched words were converted to regular expressions containing \\W, which handled… only ASCII characters. Using \[^\[:word\]\] instead ensures that UTF-8 characters are also handled correctly.

---

_[View the full topic](https://meta.discourse.org/t/test-watched-words-is-broken/267026)._
