Skip to content

Improved verification of DOM string IRI (github issue #2). #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions src/JsonLD/Core/JsonLdProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,25 @@ public static JArray Expand(JToken input, JsonLdOptions opts)
{
// 1)
// TODO: look into java futures/promises
// 2) TODO: better verification of DOMString IRI
if (input.Type == JTokenType.String && ((string)input).Contains(":"))

// 2) verification of DOMString IRI
bool isIriString = input.Type == JTokenType.String;
if (isIriString)
{
bool hasColon = false;
foreach (var c in ((string) input))
{
if (c == ':')
hasColon = true;
if (!hasColon && (c == '{' || c == '['))
{
isIriString = false;
break;
}
}
}

if (isIriString)
{
try
{
Expand Down
2 changes: 1 addition & 1 deletion src/JsonLD/Core/JsonLdUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ internal static void MergeCompactedValue(JObject obj, string
public static bool IsAbsoluteIri(string value)
{
// TODO: this is a bit simplistic!
return value.Contains(":");
return value != null && value.Contains(":");
}

/// <summary>Returns true if the given value is a subject with properties.</summary>
Expand Down
2 changes: 1 addition & 1 deletion src/JsonLD/Util/JavaCompat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static bool SafeCompare<T>(this JToken token, T val)
{
try
{
return token.Value<T>().Equals(val);
return token == null ? val == null : token.Value<T>().Equals(val);
}
catch
{
Expand Down