1

私がやること:

  • Firebugが機能していることを確認してください。
  • isWrappedInParens()関数にブレークポイントを設定します。
  • 私のウェブアプリに移動します。
  • isWrappedInParens()の呼び出しをトリガーします。
  • isWrappedInParens()をステップスルーします。すべてがうまくいきますが、「クラッシュポイント」として示されているコード行を超えて進むことはありません。
  • また、Firebugを実行したり、ブレークポイントを設定したりせずに試しましたが、それでもフリーズします。

私が気づくこと:

  • ほとんどの場合、isWrappedInParens()は正常に機能します。
  • 動作しない場合、Firefoxはフリーズします。ただし、ウィンドウを最小化/拡張/閉じることはできます。
  • また、テスト文字列が少し短い(括弧が少ない)と、Firefoxはハングしますが、最終的には正しく終了します(〜30秒)。

Firefoxをクラッシュさせる文字列の例

// Note that this is not wrapped in parentheses,
// since it is two separate sets of nested parentheses
var test = "(the OR (and) OR (and) OR (and)) AND ((to) OR (to) OR (to))";

バックグラウンド

  • ブラウザ:Firefox 3.6.18
  • webappは突堤アプリケーションです。

コード

isWrappedInParens = function(str){
    if(_.isNull(str)) {
        return false;
    }
    str = str.trim();

    var pattern = /^[(](([(][^()]+[)]|[^()]+)|[(]([(][^()]+[)]|[^()]+)+[)])+[)]$/;

    var matchesPattern;
    try{
        matchesPattern = str.match(pattern) || null; //CRASH POINT!!!!!!!!!!!
    }catch(err){
        return false; //Note that no error is ever caught from freezing
    }

    var isWrapped = !_.isUndefined(matchesPattern) && !_.isNull(matchesPattern);
    return isWrapped;
}

正規表現がどこから来たのか:

// Atoms, building blocks for the expressions
var parenAtom = "[(][^()]+[)]";
var nonParenAtom = "[^()]+";

// Expressions, building blocks for the final regular expression
var baseCase = "(" + parenAtom + "|" + nonParenAtom + ")";
var nestedCase = "[(]_base_[)]"
    .replace("_base_", baseCase);

// Regular Expression
var wholeCase = "^[(](_base_|_nested_)+[)]$"
    .replace("_base_", baseCase)
    .replace("_nested_", nestedCase);
var pattern = new RegExp(wholeCase, "");
4

1 に答える 1

1

私のコメントから:

Firefoxのバグデータベースを調べると、多くの正規表現のバグが見つかり、「指数関数的な動作」のバグとして大まかに分類されています。それらのほとんどは、ブラウザの新しいバージョンで修正されています。

このバグには、この問題に関するBrendan Eichからのコメントがいくつかあり、彼は他のいくつかのバグ(かなり古いものもあります)をリストしています。そこでの別のコメントは、Firefox 4の「正規表現のオーバーホール」をほのめかしており、それまでに多くの変更が行われたことを示唆しています。

于 2012-10-10T19:54:04.397 に答える