Skip to content

Commit 5263d56

Browse files
committed
Add allowed_content_types keyword argument to loadRemoteDocument to allow additional content types to be considered valid.
1 parent e3b319a commit 5263d56

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

lib/json/ld/api.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,9 @@ def self.fromRdf(input, useRdfType: false, useNativeTypes: false, serializer: ni
576576
# Uses built-in or provided documentLoader to retrieve a parsed document.
577577
#
578578
# @param [RDF::URI, String] url
579+
# @param [Regexp] allowed_content_types
580+
# A regular expression matching other content types allowed
581+
# beyond types for JSON and HTML.
579582
# @param [String, RDF::URI] base
580583
# Location to use as documentUrl instead of `url`.
581584
# @option options [Proc] :documentLoader
@@ -596,6 +599,7 @@ def self.fromRdf(input, useRdfType: false, useNativeTypes: false, serializer: ni
596599
# If a block is given, the result of evaluating the block is returned, otherwise, the retrieved remote document and context information unless block given
597600
# @raise [JsonLdError]
598601
def self.loadRemoteDocument(url,
602+
allowed_content_types: nil,
599603
base: nil,
600604
documentLoader: nil,
601605
extractAllScripts: false,
@@ -676,7 +680,8 @@ def self.loadRemoteDocument(url,
676680

677681
if remote_doc.contentType && validate
678682
raise IOError, "url: #{url}, contentType: #{remote_doc.contentType}" unless
679-
remote_doc.contentType.match?(/application\/(.+\+)?json|text\/html|application\/xhtml\+xml/)
683+
remote_doc.contentType.match?(/application\/(.+\+)?json|text\/html|application\/xhtml\+xml/) ||
684+
(allowed_content_types && remote_doc.contentType.match?(allowed_content_types))
680685
end
681686
block_given? ? yield(remote_doc) : remote_doc
682687
end

0 commit comments

Comments
 (0)