Skip to content

Commit

Permalink
Merge pull request #384 from imsdu/383-disable-scheme-validation
Browse files Browse the repository at this point in the history
Adds a new `UriValidationPolicy`. Deprecates `uriValidation(boolean)` option in favor of `uriValidation(UriValidationPolicy)`.
  • Loading branch information
filip26 authored Jan 30, 2025
2 parents 86dcb15 + 0d43fe3 commit 984dc49
Show file tree
Hide file tree
Showing 23 changed files with 330 additions and 52 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.apicatalog</groupId>
<artifactId>titanium</artifactId>
<version>1.4.1</version>
<version>1.5.0-SNAPSHOT</version>
<relativePath>pom_parent.xml</relativePath>
</parent>
<artifactId>titanium-json-ld</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion pom_jre8.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.apicatalog</groupId>
<artifactId>titanium</artifactId>
<version>1.4.1</version>
<version>1.5.0-SNAPSHOT</version>
<relativePath>pom_parent.xml</relativePath>
</parent>
<artifactId>titanium-json-ld-jre8</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion pom_parent.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.apicatalog</groupId>
<artifactId>titanium</artifactId>
<version>1.4.1</version>
<version>1.5.0-SNAPSHOT</version>
<packaging>pom</packaging>

<name>Titanium JSON-LD 1.1</name>
Expand Down
21 changes: 17 additions & 4 deletions src/main/java/com/apicatalog/jsonld/JsonLdOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.apicatalog.jsonld.loader.DocumentLoader;
import com.apicatalog.jsonld.loader.SchemeRouter;

import com.apicatalog.jsonld.uri.UriValidationPolicy;
import jakarta.json.JsonObject;
import jakarta.json.JsonValue;

Expand Down Expand Up @@ -57,7 +58,7 @@ public enum ProcessingPolicy {
/* default values */
public static final boolean DEFAULT_RDF_STAR = false;
public static final boolean DEFAULT_NUMERIC_ID = false;
public static final boolean DEFAULT_URI_VALIDATION = true;
public static final UriValidationPolicy DEFAULT_URI_VALIDATION = UriValidationPolicy.Full;

/**
* The base IRI to use when expanding or compacting the document. If set, this
Expand Down Expand Up @@ -132,7 +133,7 @@ public enum ProcessingPolicy {
// document cache
private Cache<String, Document> documentCache;

private boolean uriValidation;
private UriValidationPolicy uriValidation;

private Duration timeout;

Expand Down Expand Up @@ -488,9 +489,15 @@ public void setRdfStar(boolean rdfStar) {
* Enabled by default.
* </p>
*
* @return true if validation is enabled
* @deprecated use <code>JsonLdOptions#getUriValidation</code>
* @return true if full validation is enabled
*/
@Deprecated
public boolean isUriValidation() {
return uriValidation == UriValidationPolicy.Full;
}

public UriValidationPolicy getUriValidation() {
return uriValidation;
}

Expand All @@ -505,10 +512,16 @@ public boolean isUriValidation() {
* Enabled by default.
* </p>
*
* @deprecated use <code>JsonLdOptions#setUriValidation(com.apicatalog.jsonld.uri.UriValidationPolicy)</code>
* @param enabled set <code>true</code> to enable validation
*/
@Deprecated
public void setUriValidation(boolean enabled) {
this.uriValidation = enabled;
this.uriValidation = UriValidationPolicy.of(enabled);
}

public void setUriValidation(UriValidationPolicy uriValidation) {
this.uriValidation = uriValidation;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public ActiveContextBuilder newContext() {
}

public UriExpansion uriExpansion() {
return UriExpansion.with(this).uriValidation(runtime.isUriValidation());
return UriExpansion.with(this).uriValidation(runtime.getUriValidation());
}

public ValueExpansion valueExpansion() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.apicatalog.jsonld.lang.LanguageTag;
import com.apicatalog.jsonld.uri.UriUtils;

import com.apicatalog.jsonld.uri.UriValidationPolicy;
import jakarta.json.JsonArray;
import jakarta.json.JsonObject;
import jakarta.json.JsonString;
Expand Down Expand Up @@ -270,7 +271,7 @@ public void create(final String term) throws JsonLdError {
&& activeContext.runtime().isV10())
// 12.4.
|| (Keywords.noneMatch(expandedTypeString, Keywords.ID, Keywords.JSON, Keywords.NONE, Keywords.VOCAB)
&& UriUtils.isNotAbsoluteUri(expandedTypeString, true))) {
&& UriUtils.isNotAbsoluteUri(expandedTypeString, UriValidationPolicy.Full))) {
throw new JsonLdError(JsonLdErrorCode.INVALID_TYPE_MAPPING);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.apicatalog.jsonld.lang.Keywords;
import com.apicatalog.jsonld.lang.Utils;
import com.apicatalog.jsonld.uri.UriUtils;
import com.apicatalog.jsonld.uri.UriValidationPolicy;
import com.apicatalog.rdf.Rdf;
import com.apicatalog.rdf.RdfDataset;
import com.apicatalog.rdf.RdfResource;
Expand All @@ -50,7 +51,7 @@ public final class JsonLdToRdf {
// optional
private boolean produceGeneralizedRdf;
private RdfDirection rdfDirection;
private boolean uriValidation;
private UriValidationPolicy uriValidation;

private JsonLdToRdf(NodeMap nodeMap, RdfDataset dataset) {
this.nodeMap = nodeMap;
Expand Down Expand Up @@ -202,7 +203,15 @@ public RdfDataset build() throws JsonLdError {
return dataset;
}

/**
* @deprecated use <code>JsonLdToRdf#uriValidation(com.apicatalog.jsonld.uri.UriValidationPolicy)</code>
*/
@Deprecated
public JsonLdToRdf uriValidation(boolean uriValidation) {
return uriValidation(UriValidationPolicy.of(uriValidation));
}

public JsonLdToRdf uriValidation(UriValidationPolicy uriValidation) {
this.uriValidation = uriValidation;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.apicatalog.jsonld.JsonLdOptions.RdfDirection;
import com.apicatalog.jsonld.flattening.NodeMap;
import com.apicatalog.jsonld.json.JsonUtils;
import com.apicatalog.jsonld.uri.UriValidationPolicy;
import com.apicatalog.rdf.Rdf;
import com.apicatalog.rdf.RdfTriple;
import com.apicatalog.rdf.RdfValue;
Expand All @@ -46,7 +47,7 @@ final class ListToRdf {

// optional
private RdfDirection rdfDirection;
private boolean uriValidation;
private UriValidationPolicy uriValidation;

private ListToRdf(final JsonArray list, final List<RdfTriple> triples, NodeMap nodeMap) {
this.list = list;
Expand Down Expand Up @@ -120,7 +121,15 @@ public RdfValue build() throws JsonLdError {
return Rdf.createBlankNode(bnodes[0]);
}

/**
* @deprecated use <code>ListToRdf#uriValidation(com.apicatalog.jsonld.uri.UriValidationPolicy)</code>
*/
@Deprecated
public ListToRdf uriValidation(boolean uriValidation) {
return uriValidation(UriValidationPolicy.of(uriValidation));
}

public ListToRdf uriValidation(UriValidationPolicy uriValidation) {
this.uriValidation = uriValidation;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import com.apicatalog.jsonld.lang.NodeObject;
import com.apicatalog.jsonld.lang.ValueObject;
import com.apicatalog.jsonld.uri.UriUtils;
import com.apicatalog.jsonld.uri.UriValidationPolicy;
import com.apicatalog.rdf.Rdf;
import com.apicatalog.rdf.RdfLiteral;
import com.apicatalog.rdf.RdfResource;
Expand Down Expand Up @@ -71,7 +72,7 @@ final class ObjectToRdf {

// optional
private RdfDirection rdfDirection;
private boolean uriValidation;
private UriValidationPolicy uriValidation;

private ObjectToRdf(JsonObject item, List<RdfTriple> triples, NodeMap nodeMap) {
this.item = item;
Expand Down Expand Up @@ -295,7 +296,15 @@ private static final String toXsdDouble(BigDecimal bigDecimal) {
return xsdNumberFormat.format(bigDecimal);
}

/**
* @deprecated use <code>Object#uriValidation(com.apicatalog.jsonld.uri.UriValidationPolicy)</code>
*/
@Deprecated
public ObjectToRdf uriValidation(boolean uriValidation) {
return uriValidation(UriValidationPolicy.of(uriValidation));
}

public ObjectToRdf uriValidation(UriValidationPolicy uriValidation) {
this.uriValidation = uriValidation;
return this;
}
Expand Down
12 changes: 11 additions & 1 deletion src/main/java/com/apicatalog/jsonld/expansion/UriExpansion.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.apicatalog.jsonld.uri.UriResolver;
import com.apicatalog.jsonld.uri.UriUtils;

import com.apicatalog.jsonld.uri.UriValidationPolicy;
import jakarta.json.JsonObject;
import jakarta.json.JsonString;
import jakarta.json.JsonValue;
Expand All @@ -51,7 +52,7 @@ public final class UriExpansion {
// optional
private boolean documentRelative;
private boolean vocab;
private boolean uriValidation;
private UriValidationPolicy uriValidation;

private JsonObject localContext;
private Map<String, Boolean> defined;
Expand Down Expand Up @@ -206,7 +207,16 @@ private String expandResult(final String result) {
return result;
}


/**
* @deprecated use <code>UriExpansion#uriValidation(com.apicatalog.jsonld.uri.UriValidationPolicy)</code>
*/
@Deprecated
public UriExpansion uriValidation(boolean uriValidation) {
return uriValidation(UriValidationPolicy.of(uriValidation));
}

public UriExpansion uriValidation(UriValidationPolicy uriValidation) {
this.uriValidation = uriValidation;
return this;
}
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/com/apicatalog/jsonld/framing/Frame.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.apicatalog.jsonld.lang.ValueObject;
import com.apicatalog.jsonld.uri.UriUtils;

import com.apicatalog.jsonld.uri.UriValidationPolicy;
import jakarta.json.JsonArray;
import jakarta.json.JsonObject;
import jakarta.json.JsonString;
Expand Down Expand Up @@ -172,9 +173,9 @@ private static final boolean validateFrameId(JsonObject frame) {
|| idArray
.stream()
.noneMatch(item -> JsonUtils.isNotString(item)
|| UriUtils.isNotAbsoluteUri(((JsonString)item).getString(), true)));
|| UriUtils.isNotAbsoluteUri(((JsonString)item).getString(), UriValidationPolicy.Full)));
}
return JsonUtils.isString(id) && UriUtils.isAbsoluteUri(((JsonString)id).getString(), true);
return JsonUtils.isString(id) && UriUtils.isAbsoluteUri(((JsonString)id).getString(), UriValidationPolicy.Full);
}

private static final boolean validateFrameType(JsonObject frame) {
Expand All @@ -193,12 +194,12 @@ private static final boolean validateFrameType(JsonObject frame) {
|| typeArray
.stream()
.noneMatch(item -> JsonUtils.isNotString(item)
|| UriUtils.isNotAbsoluteUri(((JsonString)item).getString(), true)));
|| UriUtils.isNotAbsoluteUri(((JsonString)item).getString(), UriValidationPolicy.Full)));
}

return JsonUtils.isEmptyArray(type)
|| JsonUtils.isEmptyObject(type)
|| JsonUtils.isString(type) && UriUtils.isAbsoluteUri(((JsonString)type).getString(), true);
|| JsonUtils.isString(type) && UriUtils.isAbsoluteUri(((JsonString)type).getString(), UriValidationPolicy.Full);
}

public Set<String> keys() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static final JsonArray fromRdf(final Document document, final JsonLdOptio
.useNativeTypes(options.isUseNativeTypes())
.useRdfType(options.isUseRdfType())
.processingMode(options.getProcessingMode())
.uriValidation(options.isUriValidation())
.uriValidation(options.getUriValidation())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.apicatalog.jsonld.document.Document;
import com.apicatalog.jsonld.loader.DocumentLoader;

import com.apicatalog.jsonld.uri.UriValidationPolicy;
import jakarta.json.JsonValue;

/**
Expand Down Expand Up @@ -49,10 +50,18 @@ public void tick() throws JsonLdError {/* NOP does nothing if timeout is not set
*/
public void resetTicker() {/* NOP does nothing if timeout is not set */}

/**
* @deprecated use <code>ProcessingRuntime#getUriValidation()</code>
*/
@Deprecated
public boolean isUriValidation() {
return options.isUriValidation();
}

public UriValidationPolicy getUriValidation() {
return options.getUriValidation();
}

public boolean isV10() {
return options.getProcessingMode() != null && options.getProcessingMode().equals(JsonLdVersion.V1_0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public static final RdfDataset toRdf(Document input, final JsonLdOptions options
)
.produceGeneralizedRdf(options.isProduceGeneralizedRdf())
.rdfDirection(options.getRdfDirection())
.uriValidation(options.isUriValidation())
.uriValidation(options.getUriValidation())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.apicatalog.jsonld.lang.LanguageTag;
import com.apicatalog.jsonld.lang.Utils;
import com.apicatalog.jsonld.uri.UriUtils;
import com.apicatalog.jsonld.uri.UriValidationPolicy;
import com.apicatalog.rdf.RdfDataset;
import com.apicatalog.rdf.RdfGraph;
import com.apicatalog.rdf.RdfResource;
Expand All @@ -57,7 +58,7 @@ public final class RdfToJsonld {
private RdfDirection rdfDirection;
private boolean useNativeTypes;
private boolean useRdfType;
private boolean uriValidation;
private UriValidationPolicy uriValidation;

private JsonLdVersion processingMode;

Expand Down Expand Up @@ -434,7 +435,15 @@ protected static class Reference {
private JsonObject value;
}

/**
* @deprecated use <code>RdfToJsonld#uriValidation(com.apicatalog.jsonld.uri.UriValidationPolicy)</code>
*/
@Deprecated
public RdfToJsonld uriValidation(boolean uriValidation) {
return uriValidation(UriValidationPolicy.of(uriValidation));
}

public RdfToJsonld uriValidation(UriValidationPolicy uriValidation) {
this.uriValidation = uriValidation;
return this;
}
Expand Down
Loading

0 comments on commit 984dc49

Please sign in to comment.