测试监视的单词已损坏

在使用“监视词配置”屏幕中的“测试”功能时,“正则表达式中不允许使用带 unicode 标志的原始括号”错误会反复打印到控制台。

  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。它从 watched words serializer 获取 JSON,然后调用 word watcher,只传入了 action

几周前这本没问题,但一个 PR 引入了一个更改,添加了两个额外的参数。其中一个参数是 engine,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 个赞