代码之家  ›  专栏  ›  技术社区  ›  Sky Sanders

ysod死亡黄屏javascript regexp-语法错误

  •  6
  • Sky Sanders  · 技术社区  · 14 年前

    我是在 http://regextester.com 解析ysod,但vs抱怨语法错误。我肯定我在某个地方错过了一次逃跑,但我是一无所获。

    这是原版的。如有任何帮助,我们将不胜感激。

    var rxYSOD = /<!--\s*\[(.*?)]:(\s*.*\s(.*\n)*?)\s*(at(.*\n)*)-->/gs;
    

    更新: 科比指出了明显的问题,让我再次行动。对于那些感兴趣的人来说,这是一个有效的javascript,可以测试和解析一个用于asp.net死亡黄屏(ysod)的xmlhttprequest.responsetext。

    var rxYSOD = /<!--\s*\[(.*?)]:(\s*.*\s(.*[\n\r]*)*?)\s*(at(.*[\n\r]*)*)-->/;
    if (rxYSOD.test(text)) {
        // looks like one..
        var ysod = rxYSOD.exec(text);
        errObj = { Message: ysod[2], StackTrace: ysod[4], ExceptionType: ysod[1] };
    }
    

    @Kobi-这就是我想要解析HTML的结果和原因,尽管我得到了500:

    {
     "message": " Unknown web method ValidateUser.\r\nParameter name: methodName\r\n",
     "stackTrace": "at System.Web.Script.Services.WebServiceData.GetMethodData(String methodName)\r\n   at System.Web.Script.Services.RestHandler.CreateHandler(WebServiceData webServiceData, String methodName)\r\n   at System.Web.Script.Services.RestHandler.CreateHandler(HttpContext context)\r\n   at System.Web.Script.Services.RestHandlerFactory.GetHandler(HttpContext context, String requestType, String url, String pathTranslated)\r\n   at System.Web.Script.Services.ScriptHandlerFactory.GetHandler(HttpContext context, String requestType, String url, String pathTranslated)\r\n   at System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig)\r\n   at System.Web.HttpApplication.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()\r\n   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)\r\n",
     "exceptionType": "ArgumentException",
     "errorObject": {
      "Message": " Unknown web method ValidateUser.\r\nParameter name: methodName\r\n",
      "StackTrace": "at System.Web.Script.Services.WebServiceData.GetMethodData(String methodName)\r\n   at System.Web.Script.Services.RestHandler.CreateHandler(WebServiceData webServiceData, String methodName)\r\n   at System.Web.Script.Services.RestHandler.CreateHandler(HttpContext context)\r\n   at System.Web.Script.Services.RestHandlerFactory.GetHandler(HttpContext context, String requestType, String url, String pathTranslated)\r\n   at System.Web.Script.Services.ScriptHandlerFactory.GetHandler(HttpContext context, String requestType, String url, String pathTranslated)\r\n   at System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig)\r\n   at System.Web.HttpApplication.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()\r\n   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)\r\n",
      "ExceptionType": "ArgumentException"
     },
     "statusCode": 500,
     "servicePath": "/Authentication_JSON_AppService.axd",
     "useGet": false,
     "params": {
      "username": "testingUser",
      "password": "testingUser",
      "customCredential": null
     },
     "methodName": "ValidateUser",
     "__typeName": "Salient.ScriptModel.WebServiceError"
    }
    
    2 回复  |  直到 14 年前
        1
  •  4
  •   Kobi    14 年前

    火狐说:

    Error: invalid regular expression flag s
    Source Code:
    var rxYSOD = /<!--\s*\[(.*?)]:(\s*.*\s(.*\n)*?)\s*(at(.*\n)*)-->/gs; 
    

    在移除 s 它看起来没问题(当然,它没有经过测试,只是被正确地解析了)。

        2
  •  2
  •   Mark Byers    14 年前

    s 在javascript中无效。若要替换,请使用 replace 方法。

    推荐文章