Skip to content

Commit 87f05d0

Browse files
authored
Add three comma delimeter logic back (#323)
1 parent 152a360 commit 87f05d0

File tree

4 files changed

+49
-18
lines changed

4 files changed

+49
-18
lines changed

.pipelines/azure-pipelines-linux.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ resources:
1616
options: --entrypoint=""
1717

1818
variables:
19-
VcVersion : 1.14.30
19+
VcVersion : 1.14.31
2020
ROOT: $(Build.SourcesDirectory)
2121
CDP_DEFINITION_BUILD_COUNT: $[counter('', 0)] # needed for onebranch.pipeline.version task https://aka.ms/obpipelines/versioning
2222
ENABLE_PRS_DELAYSIGN: 1

.pipelines/azure-pipelines.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pool:
1818
vmImage: windows-latest
1919

2020
variables:
21-
VcVersion : 1.14.30
21+
VcVersion : 1.14.31
2222
ROOT: $(Build.SourcesDirectory)
2323
CDP_DEFINITION_BUILD_COUNT: $[counter('', 0)] # needed for onebranch.pipeline.version task https://aka.ms/obpipelines/versioning
2424
ENABLE_PRS_DELAYSIGN: 1

src/VirtualClient/VirtualClient.Contracts.UnitTests/Parser/TextParserExtensionsTests.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,23 @@ public void TextParserExtensionsParseVcDelimeteredParameters()
137137
{ "key3", "v3a;v3b" }
138138
}, result);
139139

140-
string complexExample = "key1=v1a;v1b,v1 c;key2=value2;key3=v 3 a;;v3b,,,key4=v4a,,,v4b;v4c;;;v4d";
140+
string exampleWithEqualSign = "key1=v1a;v1b,v1c,,,key2=value2a=value2b,,,key3=v3a;v3b";
141+
result = TextParsingExtensions.ParseVcDelimiteredParameters(exampleWithEqualSign);
142+
CollectionAssert.AreEqual(new Dictionary<string, string>
143+
{
144+
{ "key1", "v1a;v1b,v1c" },
145+
{ "key2", "value2a=value2b" },
146+
{ "key3", "v3a;v3b" }
147+
}, result);
148+
149+
string complexExample = "key1=v1a;v1b,v1 c;key2=value2;key3=v 3 a;;v3b;key4=v4a;v4b;v4c;;;v4d";
141150
result = TextParsingExtensions.ParseVcDelimiteredParameters(complexExample);
142151
CollectionAssert.AreEqual(new Dictionary<string, string>
143152
{
144153
{ "key1", "v1a;v1b,v1 c" },
145154
{ "key2", "value2" },
146155
{ "key3", "v 3 a;;v3b" },
147-
{ "key4", "v4a,,,v4b;v4c;;;v4d" }
156+
{ "key4", "v4a;v4b;v4c;;;v4d" }
148157
}, result);
149158
}
150159
}

src/VirtualClient/VirtualClient.Contracts/Parser/TextParsingExtensions.cs

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -111,23 +111,45 @@ public static IDictionary<string, string> Sectionize(string text, Regex delimite
111111
public static IDictionary<string, IConvertible> ParseVcDelimiteredParameters(string text)
112112
{
113113
IDictionary<string, IConvertible> delimitedValues = new Dictionary<string, IConvertible>(StringComparer.OrdinalIgnoreCase);
114-
string[] segments = text.Split('=', StringSplitOptions.TrimEntries);
115-
// Only start at second segment and end at second to last segment
116-
// Because first segment is the key for first pair, and last segment is the value for last pair.
117-
string key = segments[0];
118-
for (int i = 1; i < segments.Length - 1; i++)
114+
115+
if (text.Contains(",,,"))
119116
{
120-
// This is just to
121-
int lastCommaIndex = segments[i].LastIndexOf(",,,");
122-
int lastSemicolonIndex = segments[i].LastIndexOf(';');
123-
int splitIndex = Math.Max(lastCommaIndex, lastSemicolonIndex);
124-
125-
string value = segments[i].Substring(0, splitIndex);
126-
delimitedValues.Add(key, value);
127-
key = segments[i].Substring(splitIndex).Trim(';').Trim(',');
117+
// If the list contains three comma",,,", use this as delimeter
118+
string[] delimitedProperties = text.Split(",,,", StringSplitOptions.RemoveEmptyEntries);
119+
120+
if (delimitedProperties?.Any() == true)
121+
{
122+
foreach (string property in delimitedProperties)
123+
{
124+
if (property.Contains("=", StringComparison.InvariantCultureIgnoreCase))
125+
{
126+
string key = property.Substring(0, property.IndexOf("=", StringComparison.Ordinal));
127+
string value = property.Substring(property.IndexOf("=", StringComparison.Ordinal) + 1);
128+
delimitedValues[key.Trim()] = value.Trim();
129+
}
130+
}
131+
}
128132
}
133+
else
134+
{
135+
string[] segments = text.Split('=', StringSplitOptions.TrimEntries);
136+
// Only start at second segment and end at second to last segment
137+
// Because first segment is the key for first pair, and last segment is the value for last pair.
138+
string key = segments[0];
139+
for (int i = 1; i < segments.Length - 1; i++)
140+
{
141+
// This is just to
142+
int lastCommaIndex = segments[i].LastIndexOf(",,,");
143+
int lastSemicolonIndex = segments[i].LastIndexOf(';');
144+
int splitIndex = Math.Max(lastCommaIndex, lastSemicolonIndex);
145+
146+
string value = segments[i].Substring(0, splitIndex);
147+
delimitedValues.Add(key, value);
148+
key = segments[i].Substring(splitIndex).Trim(';').Trim(',');
149+
}
129150

130-
delimitedValues.Add(key, segments[segments.Length - 1]);
151+
delimitedValues.Add(key, segments[segments.Length - 1]);
152+
}
131153

132154
return delimitedValues;
133155
}

0 commit comments

Comments
 (0)