Skip to content

Commit 0f20f6c

Browse files
committed
Fix #176.
Properly parse items that contain a '=' and don't lose metadata hanging off of them.
1 parent 47d8f32 commit 0f20f6c

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

src/StructuredLogger.Tests/ItemGroupParserTests.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,33 @@ public void AddItemWithMultilineMetadata()
1515
AdditionalDependencies=kernel32.lib;user32.lib;
1616
;", MessageProcessor.OutputItemsMessagePrefix, new StringCache());
1717
}
18+
19+
/// <summary>
20+
/// https://github.com/KirillOsenkov/MSBuildStructuredLog/issues/176
21+
/// </summary>
22+
[Fact]
23+
public void ParseSuggestedBindingRedirectsMetadata()
24+
{
25+
var parameter = ItemGroupParser.ParsePropertyOrItemList(@"Output Item(s):
26+
SuggestedBindingRedirects=
27+
Microsoft.Build, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
28+
MaxVersion=15.1.0.0
29+
Microsoft.VisualStudio.Validation, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
30+
MaxVersion=15.3.0.0",
31+
MessageProcessor.OutputItemsMessagePrefix, new StringCache()) as Parameter;
32+
Assert.True(parameter != null);
33+
Assert.True(parameter.Children.Count == 2);
34+
35+
var item = parameter.FirstChild as Item;
36+
Assert.True(item != null);
37+
38+
var metadata = item.FirstChild as Metadata;
39+
Assert.True(metadata != null);
40+
41+
Assert.Equal("SuggestedBindingRedirects", parameter.Name);
42+
Assert.Equal("Microsoft.Build, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", item.Text);
43+
Assert.Equal("MaxVersion", metadata.Name);
44+
Assert.Equal("15.1.0.0", metadata.Value);
45+
}
1846
}
1947
}

src/StructuredLogger/Construction/ItemGroupParser.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,23 @@ public static object ParsePropertyOrItemList(string message, string prefix, Stri
9999
}
100100
break;
101101
case 16:
102+
if (currentItem == null && currentProperty != null)
103+
{
104+
// we incorrectly interpreted the previous line as Property, not Item (because it had '=')
105+
// and so we created a property out of name/value.
106+
// Fix this by turning it into an Item.
107+
if (parameter.LastChild == currentProperty)
108+
{
109+
currentItem = new Item
110+
{
111+
Text = currentProperty.Name + "=" + currentProperty.Value
112+
};
113+
parameter.Children.RemoveAt(parameter.Children.Count - 1);
114+
currentProperty = null;
115+
parameter.AddChild(currentItem);
116+
}
117+
}
118+
102119
if (currentItem != null)
103120
{
104121
var span16 = lineSpan.Skip(16);

src/StructuredLogger/ObjectModel/TreeNode.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,32 @@ public virtual T FindLastChild<T>()
267267
return default(T);
268268
}
269269

270+
public object FirstChild
271+
{
272+
get
273+
{
274+
if (HasChildren)
275+
{
276+
return Children[0];
277+
}
278+
279+
return null;
280+
}
281+
}
282+
283+
public object LastChild
284+
{
285+
get
286+
{
287+
if (HasChildren)
288+
{
289+
return Children[Children.Count - 1];
290+
}
291+
292+
return null;
293+
}
294+
}
295+
270296
public virtual T FindLastDescendant<T>(Predicate<T> predicate = null)
271297
{
272298
if (HasChildren)

0 commit comments

Comments
 (0)