Skip to content

Commit 697ac0d

Browse files
committed
Set the result encoding of CGI.encode to UTF-8.
1 parent 8d19c2c commit 697ac0d

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

lib/rdf/model/uri.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,7 @@ def user=(value)
902902
# Normalized version of user
903903
# @return [String]
904904
def normalized_user
905-
URI.encode(CGI.unescape(user), /[^#{IUNRESERVED}|#{SUB_DELIMS}]/).encode(Encoding::UTF_8) if user
905+
URI.encode(CGI.unescape(user), /[^#{IUNRESERVED}|#{SUB_DELIMS}]/).force_encoding(Encoding::UTF_8) if user
906906
end
907907

908908
##
@@ -928,7 +928,7 @@ def password=(value)
928928
# Normalized version of password
929929
# @return [String]
930930
def normalized_password
931-
URI.encode(CGI.unescape(password), /[^#{IUNRESERVED}|#{SUB_DELIMS}]/).encode(Encoding::UTF_8) if password
931+
URI.encode(CGI.unescape(password), /[^#{IUNRESERVED}|#{SUB_DELIMS}]/).force_encoding(Encoding::UTF_8) if password
932932
end
933933

934934
HOST_FROM_AUTHORITY_RE = /(?:[^@]+@)?([^:]+)(?::.*)?$/.freeze
@@ -1295,7 +1295,7 @@ def normalize_segment(value, expr, downcase = false)
12951295
value = value.dup.force_encoding(Encoding::UTF_8)
12961296
decoded = CGI.unescape(value)
12971297
decoded.downcase! if downcase
1298-
URI.encode(decoded, /[^(?:#{expr})]/).encode(Encoding::UTF_8)
1298+
URI.encode(decoded, /[^(?:#{expr})]/).force_encoding(Encoding::UTF_8)
12991299
end
13001300
end
13011301

spec/model_uri_spec.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,14 +470,18 @@
470470
"urn" => [
471471
"urn:ex:s001",
472472
"urn:ex:s001"
473+
],
474+
"utf-8" => [
475+
"Dürst",
476+
"Dürst"
473477
]
474478
}.each do |name, (input, output)|
475479
it "#canonicalize #{name}" do
476480
u1 = RDF::URI(input)
477481
u2 = RDF::URI(output)
478482
expect(u1.canonicalize.hash).to eq u2.hash
479483
expect(u1.canonicalize.to_s).to eq u2.to_s
480-
expect(u1).to eq u1
484+
expect(u1.canonicalize).to eq u1.canonicalize
481485
end
482486
end
483487
it "#canonicalize! alters resource" do

0 commit comments

Comments
 (0)