fix(automations): escape regex metacharacters in variable names before interpolation

オープン 初心者向け
#62 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
82/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
typescript
領域
backend, testing

調査の方向性

まず apps/api/src/instagram/services/instagram-automation-runner.service.ts、特に変数名を使って正規表現を組み立てている resumeWaitingExecution と triggerMatchingAutomations を確認してください。置換の流れを追い、関連するユニットテストを見つけて、price($) や item[0] のような名前のテストを追加してください。特殊文字でエラーが発生せず、通常の名前が大文字と小文字を区別せずに両方のテンプレート形式で引き続き一致すれば完了です。

索引モデルが issue の本文から書いたものです。

説明

backend good first issue
Problem Description

In apps/api/src/instagram/services/instagram-automation-runner.service.ts (resumeWaitingExecution lines 459-462 and triggerMatchingAutomations lines 826-829), dynamic variable substitution constructs RegExp instances directly from varName without escaping:

replyText = replyText.replace(new RegExp(`\\{\\{${varName}\\}\\}`, 'gi'), String(varVal));
replyText = replyText.replace(new RegExp(`\\{${varName}\\}`, 'gi'), String(varVal));

If varName contains any regex metacharacters (such as (, ), [, ], +, *, ?, ., $, ^, \), new RegExp(...) throws a SyntaxError at runtime and aborts the automation execution.


Expected Behavior
  1. Variable names containing special characters must never throw SyntaxError during template replacement.
  2. Normal variable names (e.g., promo_code, email, name) continue to match {{varName}} and {varName} case-insensitively without any change in behavior.

Where to Look
  • apps/api/src/instagram/services/instagram-automation-runner.service.ts (lines 459-462, 826-829)

Solution / Implementation Guide
  1. Add a small helper function (e.g., escapeRegExp(str: string): string):
    const escapeRegExp = (str: string) => str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
    
  2. Use const safeVar = escapeRegExp(varName); in both resumeWaitingExecution and triggerMatchingAutomations before building new RegExp(...).
  3. Add a unit test verifying a variable name like price($) or item[0] interpolates safely without throwing.
主要言語
TypeScript
スター
2
フォーク
1
平均マージ
6分
マージ済み PR(30日)
27

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

sumamakhan761/tryinstance のほかの issue

sumamakhan761/tryinstance の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。