Skip to content
This repository has been archived by the owner on Apr 30, 2021. It is now read-only.

Commit

Permalink
Merge pull request #77 from bjorg/DR-103
Browse files Browse the repository at this point in the history
DR-103 Building XDoc from key-value pairs can build wrong document.
  • Loading branch information
bjorg committed Feb 1, 2013
2 parents 438e012 + 81bf4c8 commit e3194f0
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 8 deletions.
3 changes: 3 additions & 0 deletions src/MindTouchDream.sln.DotSettings
@@ -0,0 +1,3 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/FilterSettingsManager/CoverageFilterXml/@EntryValue">&lt;data&gt;&lt;IncludeFilters /&gt;&lt;ExcludeFilters /&gt;&lt;/data&gt;</s:String>
<s:String x:Key="/Default/FilterSettingsManager/AttributeFilterXml/@EntryValue">&lt;data /&gt;</s:String></wpf:ResourceDictionary>
2 changes: 1 addition & 1 deletion src/mindtouch.core/mindtouch.core.csproj
Expand Up @@ -41,7 +41,7 @@
<DefineConstants>TRACE;DEBUG;DEBUG_DREAM</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<NoWarn>1911,1591</NoWarn>
<NoWarn>1591</NoWarn>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<DocumentationFile>..\bin\mindtouch.core.xml</DocumentationFile>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/mindtouch.dream.test/mindtouch.dream.test.csproj
Expand Up @@ -41,7 +41,7 @@
<DefineConstants>TRACE;DEBUG;DEBUG_DREAM</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<NoWarn>1911,1591</NoWarn>
<NoWarn>1591</NoWarn>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<DocumentationFile>..\bin\mindtouch.dream.test.xml</DocumentationFile>
</PropertyGroup>
Expand Down
15 changes: 15 additions & 0 deletions src/mindtouch.dream/Collections/DictionaryUtil.cs
Expand Up @@ -118,6 +118,21 @@ public static class DictionaryUtil {
}
return dictionary;
}

/// <summary>
/// Remove all keys from supplied dictionary.
/// </summary>
/// <returns>Keys to remove from dictionary.</returns>
/// <param name="dictionary">Dictionary to modify.</param>
/// <param name="keys">Keys to remove.</param>
/// <typeparam name="TKey">Dictionary key type.</typeparam>
/// <typeparam name="TValue">Dictionary value type.</typeparam>
public static IDictionary<TKey, TValue> RemoveKeys<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, IEnumerable<TKey> keys) {
foreach(var key in keys) {
dictionary.Remove(key);
}
return dictionary;
}
}
}

2 changes: 2 additions & 0 deletions src/mindtouch.dream/IO/StreamUtil.cs
Expand Up @@ -103,7 +103,9 @@ public static class StreamUtil {
/// <param name="stream">Target <see cref="Stream"/></param>
/// <returns><see langword="true"/> If the <see cref="Stream"/> contents are in memory</returns>
public static bool IsStreamMemorized(this Stream stream) {
#pragma warning disable 612,618
return (stream is ChunkedMemoryStream) || (stream is MemoryStream);
#pragma warning restore 612,618
}

/// <summary>
Expand Down
8 changes: 4 additions & 4 deletions src/mindtouch.dream/Xml/XDoc.cs
Expand Up @@ -1563,7 +1563,7 @@ public class XDoc : IEnumerable<XDoc>, ICloneable {
}

// check if path is empty
XDoc cursor = Copy();
XDoc cursor = CreateSelection(this);
if(xpath.Length > 0) {

// split path
Expand Down Expand Up @@ -1604,13 +1604,13 @@ public class XDoc : IEnumerable<XDoc>, ICloneable {
XDoc current = cursor[token];
while(--count >= 0) {
if(current.IsEmpty) {
current = cursor.Start(token).Copy();
current = CreateSelection(cursor.Start(token));
cursor.End();
}
current = current.Next;
}
if(current.IsEmpty) {
current = cursor.Start(token).Copy();
current = CreateSelection(cursor.Start(token));
cursor.End();
}

Expand All @@ -1621,7 +1621,7 @@ public class XDoc : IEnumerable<XDoc>, ICloneable {

// add one node
if(current.IsEmpty) {
current = cursor.Start(token).Copy();
current = CreateSelection(cursor.Start(token));
cursor.End();
}
cursor = current;
Expand Down
4 changes: 2 additions & 2 deletions src/mindtouch.dream/mindtouch.dream.csproj
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand Down Expand Up @@ -43,7 +43,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<NoWarn>1911,1591</NoWarn>
<NoWarn>1591</NoWarn>
<DocumentationFile>..\bin\mindtouch.dream.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
Expand Down
12 changes: 12 additions & 0 deletions src/tests/DreamMisc/XDoc-Test.cs
Expand Up @@ -362,6 +362,18 @@ public class XDocTest {
Assert.AreEqual(expected, text, "xpost-xml did not match");
}

[Test]
public void XPost2() {
var keyvalues = new[] {
new KeyValuePair<string, string>("a/b", "123"),
new KeyValuePair<string, string>("a/c", "456"),
new KeyValuePair<string, string>("x/a/d", "789"),
};
var doc = XDocFactory.From(keyvalues, "root");
var text = doc.ToString();
Assert.AreEqual("<root><a><b>123</b><c>456</c></a><x><a><d>789</d></a></x></root>", text);
}

[Test]
public void XmlContents() {
XDoc doc = new XDoc("test");
Expand Down

0 comments on commit e3194f0

Please sign in to comment.