File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -112,8 +112,9 @@ class URI
112112 ) . freeze
113113
114114 # Characters in a PName which must be escaped
115- PN_ESCAPE_CHARS = /[~\. \- !\$ &'\( \) \* \+ ,;=\/ \? \# @%_]/ . freeze
116- PN_ESCAPES = /\\ #{ PN_ESCAPE_CHARS } / . freeze
115+ # Note: not all reserved characters need to be escaped in SPARQL/Turtle, but they must be unescaped when encountered
116+ PN_ESCAPE_CHARS = /[~\. !\$ &'\( \) \* \+ ,;=\/ \? \# @%]/ . freeze
117+ PN_ESCAPES = /\\ #{ Regexp . union ( PN_ESCAPE_CHARS , /[\- _]/ ) } / . freeze
117118
118119 ##
119120 # Cache size may be set through {RDF.config} using `uri_cache_size`.
Original file line number Diff line number Diff line change @@ -389,7 +389,7 @@ def expand_pname(pname)
389389 return pname unless pname . is_a? ( String ) || pname . is_a? ( Symbol )
390390 prefix , suffix = pname . to_s . split ( ":" , 2 )
391391 # Unescape escaped PN_ESCAPE_CHARS
392- if suffix . match? ( / \\ #{ RDF ::URI ::PN_ESCAPE_CHARS } / )
392+ if suffix . match? ( RDF ::URI ::PN_ESCAPES )
393393 suffix = suffix . gsub ( RDF ::URI ::PN_ESCAPES ) { |matched | matched [ 1 ..-1 ] }
394394 end
395395 if prefix == "rdf"
Original file line number Diff line number Diff line change 890890
891891 context "escapes" do
892892 {
893- "http://example.org/c-" => 'ex:c\-' ,
894893 "http://example.org/c!" => 'ex:c\!' ,
895894 "http://example.org/c$" => 'ex:c\$' ,
896895 "http://example.org/c&" => 'ex:c\&' ,
899898 "http://example.org/c*+" => 'ex:c\*\+' ,
900899 "http://example.org/c;=" => 'ex:c\;\=' ,
901900 "http://example.org/c/#" => 'ex:c\/\#' ,
902- "http://example.org/c@_ " => 'ex:c\@\_ ' ,
901+ "http://example.org/c@" => 'ex:c\@' ,
903902 "http://example.org/c:d?" => 'ex:c:d\?' ,
904903 "http://example.org/c~z." => 'ex:c\~z\.' ,
905904 } . each do |orig , result |
910909 expect ( pname ) . to eql result
911910 end
912911 end
912+
913+ {
914+ "http://example.org/c-" => 'ex:c\-' ,
915+ "http://example.org/c_" => 'ex:c\_' ,
916+ } . each do |orig , result |
917+ it "does not #{ orig } => #{ result } " do
918+ uri = RDF ::URI ( orig )
919+ pname = uri . pname ( prefixes : { ex : "http://example.org/" } )
920+ expect ( uri ) . to be_valid
921+ expect ( pname ) . not_to eql result
922+ end
923+ end
913924 end
914925 end
915926
You can’t perform that action at this time.
0 commit comments