Skip to content

C#: Encode " in BuildDisplayName #5947

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ public static void BuildDisplayName(this ITypeSymbol type, Context cx, TextWrite
var elementType = array.ElementType;
if (elementType.MetadataName.Contains("`"))
{
trapFile.Write(elementType.Name);
trapFile.Write(TrapExtensions.EncodeString(elementType.Name));
return;
}
elementType.BuildDisplayName(cx, trapFile);
Expand Down Expand Up @@ -480,7 +480,7 @@ private static void BuildNamedTypeDisplayName(this INamedTypeSymbol namedType, C
}
else
{
trapFile.Write(namedType.Name);
trapFile.Write(TrapExtensions.EncodeString(namedType.Name));
}

if (namedType.IsGenericType && namedType.TypeKind != TypeKind.Error && namedType.TypeArguments.Any())
Expand Down
2 changes: 1 addition & 1 deletion csharp/extractor/Semmle.Extraction/TrapExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ private static string TruncateString(string s, ref int bytesRemaining)
return s;
}

private static string EncodeString(string s) => s.Replace("\"", "\"\"");
public static string EncodeString(string s) => s.Replace("\"", "\"\"");

/// <summary>
/// Output a string to the trap file, such that the encoded output does not exceed
Expand Down