Skip to content

Commit

Permalink
Don't normalize literal direction so that validation can work.
Browse files Browse the repository at this point in the history
  • Loading branch information
gkellogg committed Oct 24, 2023
1 parent 365dd36 commit fcde800
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/rdf/model/literal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def initialize(value, language: nil, datatype: nil, direction: nil, lexical: nil
@string = @string.encode(Encoding::UTF_8).freeze if instance_variable_defined?(:@string)
@object = @string if instance_variable_defined?(:@string) && @object.is_a?(String)
@language = language.to_s.downcase.to_sym if language
@direction = direction.to_s.downcase.to_sym if direction
@direction = direction.to_s.to_sym if direction
@datatype = RDF::URI(datatype).freeze if datatype
@datatype ||= self.class.const_get(:DATATYPE) if self.class.const_defined?(:DATATYPE)
@datatype ||= if instance_variable_defined?(:@language) && @language &&
Expand Down
16 changes: 8 additions & 8 deletions lib/rdf/ntriples/reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ class Reader < RDF::Reader
# @see http://www.w3.org/TR/turtle/
##
# Unicode regular expressions.
U_CHARS1 = Regexp.compile(<<-EOS.gsub(/\s+/, ''))
[\\u00C0-\\u00D6]|[\\u00D8-\\u00F6]|[\\u00F8-\\u02FF]|
[\\u0370-\\u037D]|[\\u037F-\\u1FFF]|[\\u200C-\\u200D]|
[\\u2070-\\u218F]|[\\u2C00-\\u2FEF]|[\\u3001-\\uD7FF]|
[\\uF900-\\uFDCF]|[\\uFDF0-\\uFFFD]|[\\u{10000}-\\u{EFFFF}]
EOS
U_CHARS2 = Regexp.compile("\\u00B7|[\\u0300-\\u036F]|[\\u203F-\\u2040]").freeze
IRI_RANGE = Regexp.compile("[[^<>\"{}\|\^`\\\\]&&[^\\x00-\\x20]]").freeze
U_CHARS1 = Regexp.compile(<<-EOS.gsub(/\s+/, ''))
[\\u00C0-\\u00D6]|[\\u00D8-\\u00F6]|[\\u00F8-\\u02FF]|
[\\u0370-\\u037D]|[\\u037F-\\u1FFF]|[\\u200C-\\u200D]|
[\\u2070-\\u218F]|[\\u2C00-\\u2FEF]|[\\u3001-\\uD7FF]|
[\\uF900-\\uFDCF]|[\\uFDF0-\\uFFFD]|[\\u{10000}-\\u{EFFFF}]
EOS
U_CHARS2 = Regexp.compile("\\u00B7|[\\u0300-\\u036F]|[\\u203F-\\u2040]").freeze
IRI_RANGE = Regexp.compile("[[^<>\"{}\|\^`\\\\]&&[^\\x00-\\x20]]").freeze

PN_CHARS_BASE = /[A-Z]|[a-z]|#{U_CHARS1}/.freeze
PN_CHARS_U = /_|#{PN_CHARS_BASE}/.freeze
Expand Down
5 changes: 5 additions & 0 deletions spec/ntriples_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@
{
"language" => '<http://subj> <http://pred> "Hello"@en .',
"direction" => '<http://subj> <http://pred> "Hello"@en--ltr .',
"direction2" => '<http://subj> <http://pred> "Hello"@en--rtl .',
}.each_pair do |name, triple|
specify "test #{name}" do
stmt = reader.new(triple, rdfstar: true).first
Expand Down Expand Up @@ -518,6 +519,10 @@
%q(<http://example/s> <http://example/p> "string"@--ltr .),
%r(Expected end of statement)
],
"xx bad dir 3" => [
%q(<http://example/s> <http://example/p> "string"@en--LTR .),
%r(Invalid Literal)
],
"nt-syntax-bad-string-05" => [
%q(<http://example/s> <http://example/p> """abc""" .),
%r(Expected end of statement \(found: .* \."\))
Expand Down

0 comments on commit fcde800

Please sign in to comment.