Skip to content

Commit 1083685

Browse files
committed
Fixes for compact, expand, error, flatten, frame conformance tests.
1 parent 110e228 commit 1083685

File tree

3 files changed

+21
-14
lines changed

3 files changed

+21
-14
lines changed

src/JsonLD/Core/Context.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public Context(JObject map) : base(map)
4444
public Context(JToken context, JsonLdOptions opts) : base(context is JObject ?
4545
(JObject)context : null)
4646
{
47+
Init(opts);
4748
}
4849

4950
// TODO: load remote context
@@ -919,10 +920,8 @@ internal virtual string CompactIri(string iri)
919920

920921
public object Clone()
921922
{
922-
JsonLD.Core.Context rval = (JsonLD.Core.Context)base.MemberwiseClone();
923-
// TODO: is this shallow copy enough? probably not, but it passes all
924-
// the tests!
925-
rval.termDefinitions = new JObject(this.termDefinitions);
923+
JsonLD.Core.Context rval = new Context(base.DeepClone(),options);
924+
rval.termDefinitions = (JObject)termDefinitions.DeepClone();
926925
return rval;
927926
}
928927

@@ -1210,7 +1209,7 @@ public virtual JToken ExpandValue(string activeProperty, JToken value)
12101209
JObject rval = new JObject();
12111210
JObject td = GetTermDefinition(activeProperty);
12121211
// 1)
1213-
if (td != null && "@id".Equals(td["@type"]))
1212+
if (td != null && td["@type"].SafeCompare("@id"))
12141213
{
12151214
// TODO: i'm pretty sure value should be a string if the @type is
12161215
// @id

src/JsonLD/Core/JsonLdApi.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,8 @@ public virtual JToken Compact(Context activeCtx, string activeProperty, JToken e
196196
if (!(result[property] is JArray))
197197
{
198198
JArray tmp = new JArray();
199-
tmp.Add(result[property] = tmp);
199+
tmp.Add(result[property]);
200+
result[property] = tmp;
200201
}
201202
if (value is JArray)
202203
{
@@ -356,7 +357,8 @@ public virtual JToken Compact(Context activeCtx, string activeProperty, JToken e
356357
if (!(mapObject[mapKey] is JArray))
357358
{
358359
tmp = new JArray();
359-
tmp.Add(mapObject[mapKey] = tmp);
360+
tmp.Add(mapObject[mapKey]);
361+
mapObject[mapKey] = tmp;
360362
}
361363
else
362364
{
@@ -388,7 +390,8 @@ public virtual JToken Compact(Context activeCtx, string activeProperty, JToken e
388390
if (!(result[itemActiveProperty] is JArray))
389391
{
390392
JArray tmp = new JArray();
391-
tmp.Add(result[itemActiveProperty] = tmp);
393+
tmp.Add(result[itemActiveProperty]);
394+
result[itemActiveProperty] = tmp;
392395
}
393396
if (compactedItem is JArray)
394397
{
@@ -763,7 +766,7 @@ public virtual JToken Expand(Context activeCtx, string activeProperty, JToken el
763766
else
764767
{
765768
// 7.5
766-
if ("@language".Equals(activeCtx.GetContainer(key)) && value is IDictionary)
769+
if ("@language".Equals(activeCtx.GetContainer(key)) && value is JObject)
767770
{
768771
// 7.5.1)
769772
expandedValue = new JArray();
@@ -1088,7 +1091,8 @@ internal virtual void GenerateNodeMap(JToken element, JObject
10881091
}
10891092
JObject graph = (JObject)nodeMap[activeGraph
10901093
];
1091-
JObject node = (JObject)(activeSubject.IsNull() ? null : graph[(string)activeSubject]);
1094+
JObject node = (JObject)((activeSubject.IsNull() || activeSubject.Type != JTokenType.String)
1095+
? null : graph[(string)activeSubject]);
10921096
// 3)
10931097
if (elem.ContainsKey("@type"))
10941098
{
@@ -1715,7 +1719,7 @@ private bool FilterNode(JsonLdApi.FramingContext state, JObject node, JObject fr
17151719
);
17161720
}
17171721
}
1718-
if (((JArray)types).Count == 1 && ((JArray)types)[0] is IDictionary
1722+
if (((JArray)types).Count == 1 && ((JArray)types)[0] is JObject
17191723
&& ((JObject)((JArray)types)[0]).Count == 0)
17201724
{
17211725
return !((JArray)nodeTypes).IsEmpty();

src/JsonLD/Util/URL.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Linq;
34
using System.Text.RegularExpressions;
45
using JsonLD.Util;
56
using Newtonsoft.Json.Linq;
@@ -233,12 +234,14 @@ public static string RemoveBase(JToken baseobj, string iri)
233234
// remove path segments that match
234235
IList<string> baseSegments = new List<string>(System.Linq.Enumerable.ToList(@base
235236
.normalizedPath.Split("/")));
237+
baseSegments = baseSegments.Where(seg => seg != "").ToList();
236238
if (@base.normalizedPath.EndsWith("/"))
237239
{
238240
baseSegments.Add(string.Empty);
239241
}
240242
IList<string> iriSegments = new List<string>(System.Linq.Enumerable.ToList(rel.normalizedPath
241243
.Split("/")));
244+
iriSegments = iriSegments.Where(seg => seg != "").ToList();
242245
if (rel.normalizedPath.EndsWith("/"))
243246
{
244247
iriSegments.Add(string.Empty);
@@ -321,7 +324,7 @@ public static string Resolve(string baseUri, string pathToResolve)
321324
// drop fragment from uri if it has one
322325
if (uri.Fragment != null)
323326
{
324-
uri = new Uri(uri.Scheme + uri.Authority + uri.AbsolutePath);
327+
uri = new Uri(uri.Scheme + "://" + uri.Authority + uri.AbsolutePath);
325328
}
326329
// add query to the end manually (as URI.resolve does it wrong)
327330
return uri.ToString() + pathToResolve;
@@ -333,12 +336,13 @@ public static string Resolve(string baseUri, string pathToResolve)
333336
{
334337
path = URL.RemoveDotSegments(uri.AbsolutePath, true);
335338
}
336-
return new Uri(uri.Scheme + uri.Authority + path + uri.Query + uri.Fragment).ToString
339+
// TODO(sblom): This line is wrong, but works.
340+
return new Uri(uri.Scheme + "://" + uri.Authority + path + uri.Query + uri.Fragment).ToString
337341
();
338342
}
339343
catch
340344
{
341-
return null;
345+
return pathToResolve;
342346
}
343347
}
344348

0 commit comments

Comments
 (0)