Fix incorrect code gen for string fields with default values

pull/5936/head
Sydney Acksman 6 years ago
parent 8a57ec847b
commit a976158b1c
  1. 36
      csharp/src/Google.Protobuf.Test/TestProtos/Unittest.cs
  2. 2
      src/google/protobuf/compiler/csharp/csharp_field_base.cc

@ -882,7 +882,7 @@ namespace Google.Protobuf.TestProtos.Proto2 {
public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, bool> DefaultBoolExtension = public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, bool> DefaultBoolExtension =
new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, bool>(73, pb::FieldCodec.ForBool(584, true)); new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, bool>(73, pb::FieldCodec.ForBool(584, true));
public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, string> DefaultStringExtension = public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, string> DefaultStringExtension =
new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, string>(74, pb::FieldCodec.ForString(594, global::System.Text.Encoding.UTF8.GetString(global::System.Convert.FromBase64String(" +aGVsbG8= +")))); new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, string>(74, pb::FieldCodec.ForString(594, global::System.Text.Encoding.UTF8.GetString(global::System.Convert.FromBase64String("aGVsbG8="))));
public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, pb::ByteString> DefaultBytesExtension = public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, pb::ByteString> DefaultBytesExtension =
new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, pb::ByteString>(75, pb::FieldCodec.ForBytes(602, pb::ByteString.FromBase64("d29ybGQ="))); new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, pb::ByteString>(75, pb::FieldCodec.ForBytes(602, pb::ByteString.FromBase64("d29ybGQ=")));
public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedEnum> DefaultNestedEnumExtension = public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, global::Google.Protobuf.TestProtos.Proto2.TestAllTypes.Types.NestedEnum> DefaultNestedEnumExtension =
@ -892,9 +892,9 @@ namespace Google.Protobuf.TestProtos.Proto2 {
public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, global::Google.Protobuf.TestProtos.Proto2.ImportEnum> DefaultImportEnumExtension = public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, global::Google.Protobuf.TestProtos.Proto2.ImportEnum> DefaultImportEnumExtension =
new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, global::Google.Protobuf.TestProtos.Proto2.ImportEnum>(83, pb::FieldCodec.ForEnum(664, x => (int) x, x => (global::Google.Protobuf.TestProtos.Proto2.ImportEnum) x, global::Google.Protobuf.TestProtos.Proto2.ImportEnum.ImportBar)); new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, global::Google.Protobuf.TestProtos.Proto2.ImportEnum>(83, pb::FieldCodec.ForEnum(664, x => (int) x, x => (global::Google.Protobuf.TestProtos.Proto2.ImportEnum) x, global::Google.Protobuf.TestProtos.Proto2.ImportEnum.ImportBar));
public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, string> DefaultStringPieceExtension = public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, string> DefaultStringPieceExtension =
new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, string>(84, pb::FieldCodec.ForString(674, global::System.Text.Encoding.UTF8.GetString(global::System.Convert.FromBase64String(" +YWJj +")))); new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, string>(84, pb::FieldCodec.ForString(674, global::System.Text.Encoding.UTF8.GetString(global::System.Convert.FromBase64String("YWJj"))));
public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, string> DefaultCordExtension = public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, string> DefaultCordExtension =
new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, string>(85, pb::FieldCodec.ForString(682, global::System.Text.Encoding.UTF8.GetString(global::System.Convert.FromBase64String(" +MTIz +")))); new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, string>(85, pb::FieldCodec.ForString(682, global::System.Text.Encoding.UTF8.GetString(global::System.Convert.FromBase64String("MTIz"))));
/// <summary> /// <summary>
/// For oneof test /// For oneof test
/// </summary> /// </summary>
@ -2415,7 +2415,7 @@ namespace Google.Protobuf.TestProtos.Proto2 {
/// <summary>Field number for the "default_string" field.</summary> /// <summary>Field number for the "default_string" field.</summary>
public const int DefaultStringFieldNumber = 74; public const int DefaultStringFieldNumber = 74;
private readonly static string DefaultStringDefaultValue = global::System.Text.Encoding.UTF8.GetString(global::System.Convert.FromBase64String(" +aGVsbG8= +")); private readonly static string DefaultStringDefaultValue = global::System.Text.Encoding.UTF8.GetString(global::System.Convert.FromBase64String("aGVsbG8="));
private string defaultString_; private string defaultString_;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
@ -2533,7 +2533,7 @@ namespace Google.Protobuf.TestProtos.Proto2 {
/// <summary>Field number for the "default_string_piece" field.</summary> /// <summary>Field number for the "default_string_piece" field.</summary>
public const int DefaultStringPieceFieldNumber = 84; public const int DefaultStringPieceFieldNumber = 84;
private readonly static string DefaultStringPieceDefaultValue = global::System.Text.Encoding.UTF8.GetString(global::System.Convert.FromBase64String(" +YWJj +")); private readonly static string DefaultStringPieceDefaultValue = global::System.Text.Encoding.UTF8.GetString(global::System.Convert.FromBase64String("YWJj"));
private string defaultStringPiece_; private string defaultStringPiece_;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
@ -2556,7 +2556,7 @@ namespace Google.Protobuf.TestProtos.Proto2 {
/// <summary>Field number for the "default_cord" field.</summary> /// <summary>Field number for the "default_cord" field.</summary>
public const int DefaultCordFieldNumber = 85; public const int DefaultCordFieldNumber = 85;
private readonly static string DefaultCordDefaultValue = global::System.Text.Encoding.UTF8.GetString(global::System.Convert.FromBase64String(" +MTIz +")); private readonly static string DefaultCordDefaultValue = global::System.Text.Encoding.UTF8.GetString(global::System.Convert.FromBase64String("MTIz"));
private string defaultCord_; private string defaultCord_;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
@ -6292,7 +6292,7 @@ namespace Google.Protobuf.TestProtos.Proto2 {
/// compile. /// compile.
/// </summary> /// </summary>
public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, string> Test = public static readonly pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, string> Test =
new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, string>(1002, pb::FieldCodec.ForString(8018, global::System.Text.Encoding.UTF8.GetString(global::System.Convert.FromBase64String(" +dGVzdA== +")))); new pb::Extension<global::Google.Protobuf.TestProtos.Proto2.TestAllExtensions, string>(1002, pb::FieldCodec.ForString(8018, global::System.Text.Encoding.UTF8.GetString(global::System.Convert.FromBase64String("dGVzdA=="))));
/// <summary> /// <summary>
/// Used to test if generated extension name is correct when there are /// Used to test if generated extension name is correct when there are
/// underscores. /// underscores.
@ -13094,7 +13094,7 @@ namespace Google.Protobuf.TestProtos.Proto2 {
/// <summary>Field number for the "utf8_string" field.</summary> /// <summary>Field number for the "utf8_string" field.</summary>
public const int Utf8StringFieldNumber = 6; public const int Utf8StringFieldNumber = 6;
private readonly static string Utf8StringDefaultValue = global::System.Text.Encoding.UTF8.GetString(global::System.Convert.FromBase64String(" +4Yi0 +")); private readonly static string Utf8StringDefaultValue = global::System.Text.Encoding.UTF8.GetString(global::System.Convert.FromBase64String("4Yi0"));
private string utf8String_; private string utf8String_;
/// <summary> /// <summary>
@ -13443,7 +13443,7 @@ namespace Google.Protobuf.TestProtos.Proto2 {
/// <summary>Field number for the "cpp_trigraph" field.</summary> /// <summary>Field number for the "cpp_trigraph" field.</summary>
public const int CppTrigraphFieldNumber = 20; public const int CppTrigraphFieldNumber = 20;
private readonly static string CppTrigraphDefaultValue = global::System.Text.Encoding.UTF8.GetString(global::System.Convert.FromBase64String(" +PyA/ID8/ID8/ID8/PyA/Py8gPz8t +")); private readonly static string CppTrigraphDefaultValue = global::System.Text.Encoding.UTF8.GetString(global::System.Convert.FromBase64String("PyA/ID8/ID8/ID8/PyA/Py8gPz8t"));
private string cppTrigraph_; private string cppTrigraph_;
/// <summary> /// <summary>
@ -13473,7 +13473,7 @@ namespace Google.Protobuf.TestProtos.Proto2 {
/// <summary>Field number for the "string_with_zero" field.</summary> /// <summary>Field number for the "string_with_zero" field.</summary>
public const int StringWithZeroFieldNumber = 23; public const int StringWithZeroFieldNumber = 23;
private readonly static string StringWithZeroDefaultValue = global::System.Text.Encoding.UTF8.GetString(global::System.Convert.FromBase64String(" +aGVsAGxv +")); private readonly static string StringWithZeroDefaultValue = global::System.Text.Encoding.UTF8.GetString(global::System.Convert.FromBase64String("aGVsAGxv"));
private string stringWithZero_; private string stringWithZero_;
/// <summary> /// <summary>
@ -13522,7 +13522,7 @@ namespace Google.Protobuf.TestProtos.Proto2 {
/// <summary>Field number for the "string_piece_with_zero" field.</summary> /// <summary>Field number for the "string_piece_with_zero" field.</summary>
public const int StringPieceWithZeroFieldNumber = 25; public const int StringPieceWithZeroFieldNumber = 25;
private readonly static string StringPieceWithZeroDefaultValue = global::System.Text.Encoding.UTF8.GetString(global::System.Convert.FromBase64String(" +YWIAYw== +")); private readonly static string StringPieceWithZeroDefaultValue = global::System.Text.Encoding.UTF8.GetString(global::System.Convert.FromBase64String("YWIAYw=="));
private string stringPieceWithZero_; private string stringPieceWithZero_;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
@ -13545,7 +13545,7 @@ namespace Google.Protobuf.TestProtos.Proto2 {
/// <summary>Field number for the "cord_with_zero" field.</summary> /// <summary>Field number for the "cord_with_zero" field.</summary>
public const int CordWithZeroFieldNumber = 26; public const int CordWithZeroFieldNumber = 26;
private readonly static string CordWithZeroDefaultValue = global::System.Text.Encoding.UTF8.GetString(global::System.Convert.FromBase64String(" +MTIAMw== +")); private readonly static string CordWithZeroDefaultValue = global::System.Text.Encoding.UTF8.GetString(global::System.Convert.FromBase64String("MTIAMw=="));
private string cordWithZero_; private string cordWithZero_;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
@ -13568,7 +13568,7 @@ namespace Google.Protobuf.TestProtos.Proto2 {
/// <summary>Field number for the "replacement_string" field.</summary> /// <summary>Field number for the "replacement_string" field.</summary>
public const int ReplacementStringFieldNumber = 27; public const int ReplacementStringFieldNumber = 27;
private readonly static string ReplacementStringDefaultValue = global::System.Text.Encoding.UTF8.GetString(global::System.Convert.FromBase64String(" +JHt1bmtub3dufQ== +")); private readonly static string ReplacementStringDefaultValue = global::System.Text.Encoding.UTF8.GetString(global::System.Convert.FromBase64String("JHt1bmtub3dufQ=="));
private string replacementString_; private string replacementString_;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
@ -16784,7 +16784,7 @@ namespace Google.Protobuf.TestProtos.Proto2 {
public const int BarStringFieldNumber = 13; public const int BarStringFieldNumber = 13;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public string BarString { public string BarString {
get { return HasBarString ? (string) bar_ : global::System.Text.Encoding.UTF8.GetString(global::System.Convert.FromBase64String(" +U1RSSU5H +")); } get { return HasBarString ? (string) bar_ : global::System.Text.Encoding.UTF8.GetString(global::System.Convert.FromBase64String("U1RSSU5H")); }
set { set {
bar_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); bar_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
barCase_ = BarOneofCase.BarString; barCase_ = BarOneofCase.BarString;
@ -16807,7 +16807,7 @@ namespace Google.Protobuf.TestProtos.Proto2 {
public const int BarCordFieldNumber = 14; public const int BarCordFieldNumber = 14;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public string BarCord { public string BarCord {
get { return HasBarCord ? (string) bar_ : global::System.Text.Encoding.UTF8.GetString(global::System.Convert.FromBase64String(" +Q09SRA== +")); } get { return HasBarCord ? (string) bar_ : global::System.Text.Encoding.UTF8.GetString(global::System.Convert.FromBase64String("Q09SRA==")); }
set { set {
bar_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); bar_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
barCase_ = BarOneofCase.BarCord; barCase_ = BarOneofCase.BarCord;
@ -16830,7 +16830,7 @@ namespace Google.Protobuf.TestProtos.Proto2 {
public const int BarStringPieceFieldNumber = 15; public const int BarStringPieceFieldNumber = 15;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public string BarStringPiece { public string BarStringPiece {
get { return HasBarStringPiece ? (string) bar_ : global::System.Text.Encoding.UTF8.GetString(global::System.Convert.FromBase64String(" +U1BJRUNF +")); } get { return HasBarStringPiece ? (string) bar_ : global::System.Text.Encoding.UTF8.GetString(global::System.Convert.FromBase64String("U1BJRUNF")); }
set { set {
bar_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); bar_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
barCase_ = BarOneofCase.BarStringPiece; barCase_ = BarOneofCase.BarStringPiece;
@ -16921,7 +16921,7 @@ namespace Google.Protobuf.TestProtos.Proto2 {
/// <summary>Field number for the "baz_string" field.</summary> /// <summary>Field number for the "baz_string" field.</summary>
public const int BazStringFieldNumber = 19; public const int BazStringFieldNumber = 19;
private readonly static string BazStringDefaultValue = global::System.Text.Encoding.UTF8.GetString(global::System.Convert.FromBase64String(" +QkFa +")); private readonly static string BazStringDefaultValue = global::System.Text.Encoding.UTF8.GetString(global::System.Convert.FromBase64String("QkFa"));
private string bazString_; private string bazString_;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute] [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
@ -21185,7 +21185,7 @@ namespace Google.Protobuf.TestProtos.Proto2 {
/// <summary>Field number for the "a" field.</summary> /// <summary>Field number for the "a" field.</summary>
public const int AFieldNumber = 1; public const int AFieldNumber = 1;
private readonly static string ADefaultValue = global::System.Text.Encoding.UTF8.GetString(global::System.Convert.FromBase64String(" +Ki8gPC0gTmVpdGhlciBzaG91bGQgdGhpcy4= +")); private readonly static string ADefaultValue = global::System.Text.Encoding.UTF8.GetString(global::System.Convert.FromBase64String("Ki8gPC0gTmVpdGhlciBzaG91bGQgdGhpcy4="));
private string a_; private string a_;
/// <summary> /// <summary>

@ -306,7 +306,7 @@ std::string FieldGeneratorBase::GetStringDefaultValueInternal(const FieldDescrip
if (descriptor->default_value_string().empty()) if (descriptor->default_value_string().empty())
return "\"\""; return "\"\"";
else else
return "global::System.Text.Encoding.UTF8.GetString(global::System.Convert.FromBase64String(\" +" + StringToBase64(descriptor->default_value_string()) + " +\"))"; return "global::System.Text.Encoding.UTF8.GetString(global::System.Convert.FromBase64String(\"" + StringToBase64(descriptor->default_value_string()) + "\"))";
} }
std::string FieldGeneratorBase::GetBytesDefaultValueInternal(const FieldDescriptor* descriptor) { std::string FieldGeneratorBase::GetBytesDefaultValueInternal(const FieldDescriptor* descriptor) {

Loading…
Cancel
Save