Skip to content

Commit fcde800

Browse files
committed
Don't normalize literal direction so that validation can work.
1 parent 365dd36 commit fcde800

3 files changed

Lines changed: 14 additions & 9 deletions

File tree

lib/rdf/model/literal.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def initialize(value, language: nil, datatype: nil, direction: nil, lexical: nil
194194
@string = @string.encode(Encoding::UTF_8).freeze if instance_variable_defined?(:@string)
195195
@object = @string if instance_variable_defined?(:@string) && @object.is_a?(String)
196196
@language = language.to_s.downcase.to_sym if language
197-
@direction = direction.to_s.downcase.to_sym if direction
197+
@direction = direction.to_s.to_sym if direction
198198
@datatype = RDF::URI(datatype).freeze if datatype
199199
@datatype ||= self.class.const_get(:DATATYPE) if self.class.const_defined?(:DATATYPE)
200200
@datatype ||= if instance_variable_defined?(:@language) && @language &&

lib/rdf/ntriples/reader.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ class Reader < RDF::Reader
5151
# @see http://www.w3.org/TR/turtle/
5252
##
5353
# Unicode regular expressions.
54-
U_CHARS1 = Regexp.compile(<<-EOS.gsub(/\s+/, ''))
55-
[\\u00C0-\\u00D6]|[\\u00D8-\\u00F6]|[\\u00F8-\\u02FF]|
56-
[\\u0370-\\u037D]|[\\u037F-\\u1FFF]|[\\u200C-\\u200D]|
57-
[\\u2070-\\u218F]|[\\u2C00-\\u2FEF]|[\\u3001-\\uD7FF]|
58-
[\\uF900-\\uFDCF]|[\\uFDF0-\\uFFFD]|[\\u{10000}-\\u{EFFFF}]
59-
EOS
60-
U_CHARS2 = Regexp.compile("\\u00B7|[\\u0300-\\u036F]|[\\u203F-\\u2040]").freeze
61-
IRI_RANGE = Regexp.compile("[[^<>\"{}\|\^`\\\\]&&[^\\x00-\\x20]]").freeze
54+
U_CHARS1 = Regexp.compile(<<-EOS.gsub(/\s+/, ''))
55+
[\\u00C0-\\u00D6]|[\\u00D8-\\u00F6]|[\\u00F8-\\u02FF]|
56+
[\\u0370-\\u037D]|[\\u037F-\\u1FFF]|[\\u200C-\\u200D]|
57+
[\\u2070-\\u218F]|[\\u2C00-\\u2FEF]|[\\u3001-\\uD7FF]|
58+
[\\uF900-\\uFDCF]|[\\uFDF0-\\uFFFD]|[\\u{10000}-\\u{EFFFF}]
59+
EOS
60+
U_CHARS2 = Regexp.compile("\\u00B7|[\\u0300-\\u036F]|[\\u203F-\\u2040]").freeze
61+
IRI_RANGE = Regexp.compile("[[^<>\"{}\|\^`\\\\]&&[^\\x00-\\x20]]").freeze
6262

6363
PN_CHARS_BASE = /[A-Z]|[a-z]|#{U_CHARS1}/.freeze
6464
PN_CHARS_U = /_|#{PN_CHARS_BASE}/.freeze

spec/ntriples_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@
322322
{
323323
"language" => '<http://subj> <http://pred> "Hello"@en .',
324324
"direction" => '<http://subj> <http://pred> "Hello"@en--ltr .',
325+
"direction2" => '<http://subj> <http://pred> "Hello"@en--rtl .',
325326
}.each_pair do |name, triple|
326327
specify "test #{name}" do
327328
stmt = reader.new(triple, rdfstar: true).first
@@ -518,6 +519,10 @@
518519
%q(<http://example/s> <http://example/p> "string"@--ltr .),
519520
%r(Expected end of statement)
520521
],
522+
"xx bad dir 3" => [
523+
%q(<http://example/s> <http://example/p> "string"@en--LTR .),
524+
%r(Invalid Literal)
525+
],
521526
"nt-syntax-bad-string-05" => [
522527
%q(<http://example/s> <http://example/p> """abc""" .),
523528
%r(Expected end of statement \(found: .* \."\))

0 commit comments

Comments
 (0)