Skip to content

Commit 834b958

Browse files
author
Michael Conrad
authored
Fixing string format, fixes #227
1 parent 2395999 commit 834b958

15 files changed

Lines changed: 57 additions & 18 deletions

src/DnsClient/DnsQuestion.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// See LICENSE file for details.
44

55
using System;
6+
using System.Globalization;
67

78
namespace DnsClient
89
{
@@ -78,7 +79,15 @@ public override string ToString()
7879
public string ToString(int offset = -32)
7980
{
8081
var printTab = offset == 0 ? string.Empty : "\t";
81-
return string.Format("{0," + offset + "} {1}{2} {1}{3}", QueryName.Original, printTab, QuestionClass, QuestionType);
82+
83+
var offsetStr = offset.ToString(provider: CultureInfo.InvariantCulture);
84+
return string.Format(
85+
CultureInfo.InvariantCulture,
86+
$"{{0,{offsetStr}}} {{1}}{{2}} {{1}}{{3}}",
87+
QueryName.Original,
88+
printTab,
89+
QuestionClass,
90+
QuestionType);
8291
}
8392
}
84-
}
93+
}

src/DnsClient/Protocol/CertRecord.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
using System;
66
using System.Collections.Generic;
7+
using System.Globalization;
78

89
namespace DnsClient.Protocol;
910

@@ -75,6 +76,6 @@ public CertRecord(ResourceRecordInfo info, int certType, int keyTag, byte algori
7576

7677
private protected override string RecordToString()
7778
{
78-
return string.Format("{0} {1} {2} {3}", CertType, KeyTag, Algorithm, PublicKeyAsString);
79+
return string.Format(CultureInfo.InvariantCulture, "{0} {1} {2} {3}", CertType, KeyTag, Algorithm, PublicKeyAsString);
7980
}
8081
}

src/DnsClient/Protocol/DnsKeyRecord.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
using System;
66
using System.Collections.Generic;
7+
using System.Globalization;
8+
using System.Linq;
79

810
namespace DnsClient.Protocol
911
{
@@ -97,7 +99,7 @@ public DnsKeyRecord(ResourceRecordInfo info, int flags, byte protocol, byte algo
9799

98100
private protected override string RecordToString()
99101
{
100-
return string.Format("{0} {1} {2} {3}", Flags, Protocol, Algorithm, PublicKeyAsString);
102+
return string.Format(CultureInfo.InvariantCulture, "{0} {1} {2} {3}", Flags, Protocol, Algorithm, PublicKeyAsString);
101103
}
102104
}
103-
}
105+
}

src/DnsClient/Protocol/DnsResourceRecord.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// See LICENSE file for details.
44

55
using System;
6+
using System.Globalization;
67

78
namespace DnsClient.Protocol
89
{
@@ -43,7 +44,9 @@ public override string ToString()
4344
public virtual string ToString(int offset = 0)
4445
{
4546
var printTab = offset == 0 ? string.Empty : "\t";
46-
return string.Format("{0," + offset + "} {1}{2} {1}{3} {1}{4} {1}{5}",
47+
return string.Format(
48+
CultureInfo.InvariantCulture,
49+
"{0," + offset.ToString(CultureInfo.InvariantCulture) + "} {1}{2} {1}{3} {1}{4} {1}{5}",
4750
DomainName,
4851
printTab,
4952
TimeToLive,

src/DnsClient/Protocol/DsRecord.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
using System;
66
using System.Collections.Generic;
7+
using System.Globalization;
78
using System.Linq;
89

910
namespace DnsClient.Protocol
@@ -71,7 +72,7 @@ public DsRecord(ResourceRecordInfo info, int keyTag, byte algorithm, byte digest
7172

7273
private protected override string RecordToString()
7374
{
74-
return string.Format("{0} {1} {2} {3}", KeyTag, Algorithm, DigestType, DigestAsString);
75+
return string.Format(CultureInfo.InvariantCulture, "{0} {1} {2} {3}", KeyTag, Algorithm, DigestType, DigestAsString);
7576
}
7677
}
77-
}
78+
}

src/DnsClient/Protocol/MXRecord.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// See LICENSE file for details.
44

55
using System;
6+
using System.Globalization;
67

78
namespace DnsClient.Protocol
89
{
@@ -67,7 +68,7 @@ public MxRecord(ResourceRecordInfo info, ushort preference, DnsString domainName
6768

6869
private protected override string RecordToString()
6970
{
70-
return string.Format("{0} {1}", Preference, Exchange);
71+
return string.Format(CultureInfo.InvariantCulture, "{0} {1}", Preference, Exchange);
7172
}
7273
}
73-
}
74+
}

src/DnsClient/Protocol/NSec3ParamRecord.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// See LICENSE file for details.
44

55
using System;
6+
using System.Globalization;
67
using System.Linq;
78

89
namespace DnsClient.Protocol
@@ -94,6 +95,7 @@ public NSec3ParamRecord(
9495
private protected override string RecordToString()
9596
{
9697
return string.Format(
98+
CultureInfo.InvariantCulture,
9799
"{0} {1} {2} {3}",
98100
HashAlgorithm,
99101
Flags,

src/DnsClient/Protocol/NSec3Record .cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
using System;
66
using System.Collections.Generic;
7+
using System.Globalization;
78
using System.Linq;
89
using DnsClient.Internal;
910

@@ -135,6 +136,7 @@ public NSec3Record(
135136
private protected override string RecordToString()
136137
{
137138
return string.Format(
139+
CultureInfo.InvariantCulture,
138140
"{0} {1} {2} {3} {4} {5}",
139141
HashAlgorithm,
140142
Flags,

src/DnsClient/Protocol/NSecRecord.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
using System;
66
using System.Collections.Generic;
7+
using System.Globalization;
78
using System.Linq;
89

910
namespace DnsClient.Protocol
@@ -79,7 +80,7 @@ public NSecRecord(ResourceRecordInfo info, DnsString nextDomainName, byte[] type
7980

8081
private protected override string RecordToString()
8182
{
82-
return string.Format("{0} {1}", NextDomainName, string.Join(" ", TypeBitMaps));
83+
return string.Format(CultureInfo.InvariantCulture, "{0} {1}", NextDomainName, string.Join(" ", TypeBitMaps));
8384
}
8485

8586
internal static IEnumerable<int> ReadBitmap(byte[] data)

src/DnsClient/Protocol/NaptrRecord.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// See LICENSE file for details.
44

55
using System;
6+
using System.Globalization;
67

78
namespace DnsClient.Protocol
89
{
@@ -230,7 +231,9 @@ public NAPtrRecord(ResourceRecordInfo info, int order, int preference, string fl
230231

231232
private protected override string RecordToString()
232233
{
233-
return string.Format("{0} {1} \"{2}\" \"{3}\" \"{4}\" {5}",
234+
return string.Format(
235+
CultureInfo.InvariantCulture,
236+
"{0} {1} \"{2}\" \"{3}\" \"{4}\" {5}",
234237
Order,
235238
Preference,
236239
Flags,
@@ -239,4 +242,4 @@ private protected override string RecordToString()
239242
Replacement);
240243
}
241244
}
242-
}
245+
}

0 commit comments

Comments
 (0)