Skip to content

Commit

Permalink
Disable secure mode for JSONLDParser
Browse files Browse the repository at this point in the history
  • Loading branch information
skodapetr committed Aug 7, 2024
1 parent 2acf10d commit 57d232b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import com.linkedpipes.etl.executor.api.v1.component.SequentialExecution;
import com.linkedpipes.etl.executor.api.v1.service.ProgressReport;
import org.eclipse.rdf4j.rio.*;
import org.eclipse.rdf4j.rio.helpers.JSONLDSettings;
import org.eclipse.rdf4j.rio.jsonld.JSONLDParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -87,6 +89,11 @@ private void loadFiles() throws LpException {
private void loadEntry(FilesDataUnit.Entry entry) throws LpException {
RDFFormat format = getFormat(entry.getFileName());
RDFParser parser = createParser(format);

if (parser instanceof JSONLDParser jsonLdParser) {
jsonLdParser.set(JSONLDSettings.SECURE_MODE, false);
}

try (InputStream fileStream = new FileInputStream(entry.toFile())) {
parser.parse(fileStream, "http://localhost/base/");
} catch (IOException | RDFHandlerException | RDFParseException ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import org.eclipse.rdf4j.rio.RDFParser;
import org.eclipse.rdf4j.rio.Rio;
import org.eclipse.rdf4j.rio.helpers.AbstractRDFHandler;
import org.eclipse.rdf4j.rio.helpers.JSONLDSettings;
import org.eclipse.rdf4j.rio.jsonld.JSONLDParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -96,8 +98,18 @@ protected RDFFormat getFormat(String fileName) throws LpException {
}

protected void loadFile(File file, RDFFormat format) throws LpException {
RDFParser parser;
try {
parser = createParser(format);
} catch(RuntimeException ex) {
throw new LpException("Can't create parser for a file: {}", file, ex);
}

if (parser instanceof JSONLDParser jsonLdParser) {
jsonLdParser.set(JSONLDSettings.SECURE_MODE, false);
}

try (InputStream stream = new FileInputStream(file)) {
RDFParser parser = createParser(format);
parser.parse(stream, "http://localhost/base/");
} catch (RuntimeException | IOException ex) {
throw new LpException("Can't load file: {}", file, ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import com.linkedpipes.etl.executor.api.v1.component.SequentialExecution;
import com.linkedpipes.etl.executor.api.v1.service.ProgressReport;
import org.eclipse.rdf4j.rio.*;
import org.eclipse.rdf4j.rio.helpers.JSONLDSettings;
import org.eclipse.rdf4j.rio.jsonld.JSONLDParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -78,6 +80,11 @@ private void loadFiles() throws LpException {
private void loadEntry(FilesDataUnit.Entry entry) throws LpException {
RDFFormat format = getFormat(entry.getFileName());
RDFParser parser = createParser(format);

if (parser instanceof JSONLDParser jsonLdParser) {
jsonLdParser.set(JSONLDSettings.SECURE_MODE, false);
}

try (InputStream fileStream = new FileInputStream(entry.toFile())) {
parser.parse(fileStream, "http://localhost/base/");
} catch (Exception ex) {
Expand Down

0 comments on commit 57d232b

Please sign in to comment.