StackTraceParser: Support StackTraces with 'http' but without the parentheses (#81)
* StackTraceParser: Support StackTraces with 'http' but without the parenteses Support for stacktraces without parenteses for the http filename * Correction for unit test * Refactored TryExtractMethodNameFromFrame(..) Method to have a single exit point If method is empty or whitespace then return null * Added UnitTest * Support for webpack stack trace
This commit is contained in:
Родитель
bc6a883ce0
Коммит
dd28b4d9cc
|
@ -81,25 +81,46 @@ namespace SourcemapToolkit.CallstackDeminifier
|
|||
/// </summary>
|
||||
private string TryExtractMethodNameFromFrame(string frame)
|
||||
{
|
||||
string methodName = null;
|
||||
|
||||
// Firefox has stackframes in the form: "c@http://localhost:19220/crashcauser.min.js:1:34"
|
||||
int atSymbolIndex = frame.IndexOf("@http", StringComparison.Ordinal);
|
||||
if (atSymbolIndex != -1)
|
||||
{
|
||||
return frame.Substring(0, atSymbolIndex).TrimStart();
|
||||
methodName = frame.Substring(0, atSymbolIndex).TrimStart();
|
||||
}
|
||||
|
||||
// Chrome and IE11 have stackframes in the form: " at d (http://chrisgocallstack.azurewebsites.net/crashcauser.min.js:1:75)"
|
||||
int atStringIndex = frame.IndexOf("at ", StringComparison.Ordinal);
|
||||
if (atStringIndex != -1)
|
||||
else
|
||||
{
|
||||
int httpIndex = frame.IndexOf(" (http", atStringIndex, StringComparison.Ordinal);
|
||||
if (httpIndex != -1)
|
||||
// Chrome and IE11 have stackframes in the form: " at d (http://chrisgocallstack.azurewebsites.net/crashcauser.min.js:1:75)"
|
||||
int atStringIndex = frame.IndexOf("at ", StringComparison.Ordinal);
|
||||
if (atStringIndex != -1)
|
||||
{
|
||||
return frame.Substring(atStringIndex, httpIndex - atStringIndex).Replace("at ", "").Trim();
|
||||
int httpIndex = frame.IndexOf(" (http", atStringIndex, StringComparison.Ordinal);
|
||||
if (httpIndex == -1)
|
||||
{
|
||||
httpIndex = frame.IndexOf(" http", atStringIndex, StringComparison.Ordinal);
|
||||
if (httpIndex != -1)
|
||||
httpIndex++; // append one char to include a blank space to be able to replace "at " correctly
|
||||
}
|
||||
|
||||
if (httpIndex != -1)
|
||||
{
|
||||
methodName = frame.Substring(atStringIndex, httpIndex - atStringIndex).Replace("at ", "").Trim();
|
||||
}
|
||||
else
|
||||
{
|
||||
var parenthesesIndex = frame.IndexOf(" (", atStringIndex, StringComparison.Ordinal);
|
||||
if (parenthesesIndex != -1)
|
||||
{
|
||||
methodName = frame.Substring(atStringIndex, parenthesesIndex - atStringIndex).Replace("at ", "").Trim();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
if (string.IsNullOrWhiteSpace(methodName))
|
||||
methodName = null;
|
||||
return methodName;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -112,6 +112,40 @@ window.onload/<@http://localhost:19220/crashcauser.min.js:1:332";
|
|||
Assert.Equal(33, result.SourcePosition.ZeroBasedColumnNumber);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TryParseSingleStackFrame_StackFrameWithWebpackLink_CorrectStackFrame()
|
||||
{
|
||||
// Arrange
|
||||
StackTraceParser stackTraceParser = new StackTraceParser();
|
||||
string frame = " at eval (webpack-internal:///./Static/jsx/InitialStep/InitialStepForm.js:167:14)";
|
||||
|
||||
// Act
|
||||
StackFrame result = stackTraceParser.TryParseSingleStackFrame(frame);
|
||||
|
||||
// Assert
|
||||
Assert.Equal("webpack-internal:///./Static/jsx/InitialStep/InitialStepForm.js", result.FilePath);
|
||||
Assert.Equal("eval", result.MethodName);
|
||||
Assert.Equal(167-1, result.SourcePosition.ZeroBasedLineNumber);
|
||||
Assert.Equal(14-1, result.SourcePosition.ZeroBasedColumnNumber);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TryParseSingleStackFrame_StackFrameWithoutParentheses_CorrectStackFrame()
|
||||
{
|
||||
// Arrange
|
||||
StackTraceParser stackTraceParser = new StackTraceParser();
|
||||
string frame = " at c http://localhost:19220/crashcauser.min.js:8:3";
|
||||
|
||||
// Act
|
||||
StackFrame result = stackTraceParser.TryParseSingleStackFrame(frame);
|
||||
|
||||
// Assert
|
||||
Assert.Equal("http://localhost:19220/crashcauser.min.js", result.FilePath);
|
||||
Assert.Equal("c", result.MethodName);
|
||||
Assert.Equal(7, result.SourcePosition.ZeroBasedLineNumber);
|
||||
Assert.Equal(2, result.SourcePosition.ZeroBasedColumnNumber);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TryParseSingleStackFrame_ChromeStackFrame_CorrectStackFrame()
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче