Skip to content
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

When there is no uri validation, do not validate the scheme #384

Merged
merged 4 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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: 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
Loading