テストで監視ワードが機能しません

watched words 設定画面で「テスト」機能を使用すると、「raw bracket is not allowed in regular expression with unicode flag」というエラーがコンソールに繰り返し表示されます。

  1. https://meta.discourse.org/admin/customize/watched_words/action/require_approval にアクセスします。
  2. ブラウザのコンソールを開きます。
  3. 「テスト」を押します。
  4. 何か入力します。
  5. エラーを確認します。

エラーは watched-words.js に由来しており、渡されている正規表現が (?:[^[:word:]]|^)(word1|word2)(?=[^[:word:]]|$) であるためです。これは Ruby では有効ですが、JavaScript では無効です。正規表現は、API https://meta.discourse.org/admin/customize/watched_words.json から取得されます。この API は、watched words serializer から JSON を取得し、このシリアライザーは action のみが渡された状態で word watcher を呼び出します。

数週間前であれば問題ありませんでしたが、PR によって 2 つの追加パラメータが導入されました。これらのパラメータの 1 つが engine で、デフォルトで Ruby に設定されており、前述の呼び出しでは指定されていません。そのため、返される正規表現は Ruby 固有のものですが、JavaScript の正規表現エンジンによって消費されます。

「いいね!」 5

テストサイトで再現できます。

  • ブロックされた「監視対象の単語」を設定します。
  • テスト機能を使用して試します。
  • コンソールで次のエラーが表示されます。
Uncaught SyntaxError: raw bracket is not allowed in regular expression with unicode flag
    createWatchedWordRegExp watched-words.js:12
    matches admin-watched-word-test.js:62
    matches admin-watched-word-test.js:61
    o handle-descriptor.js:61
    get Ember
    untrack validator.js:681
    Ember 3
    o reference.js:175
    tag reference.js:136
    track validator.js:668
    f reference.js:135
    <anonymous> runtime.js:2077
    tag reference.js:136
    track validator.js:668
    f reference.js:135
    evaluate runtime.js:2089
    _execute runtime.js:4306
    execute runtime.js:4291
    rerender runtime.js:4606
    Ember 2
    It runtime.js:4139
    Ember 3
    invoke queue.ts:201
    flush queue.ts:98
    flush deferred-action-queues.ts:75
    _end index.ts:616
    end index.ts:298
    _runExpiredTimers index.ts:739
    setTimeout handler*setTimeout platform.ts:50
    _installTimerTimeout index.ts:783
    _scheduleExpiredTimers index.ts:764
    _runExpiredTimers index.ts:738
watched-words.js:12

詳細なレポートありがとうございます。誰かに確認してもらえるか確認します。 :slight_smile: :+1:

「いいね!」 5

詳細なレポートありがとうございます @Arthri

修正されました。

「いいね!」 3