Skip to content

Commit 6df89b6

Browse files
committed
Set the result encoding of CGI.encode to UTF-8.
1 parent 9ad105e commit 6df89b6

2 files changed

Lines changed: 3 additions & 8 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}]/) if user
905+
URI.encode(CGI.unescape(user), /[^#{IUNRESERVED}|#{SUB_DELIMS}]/).encode(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}]/) if password
931+
URI.encode(CGI.unescape(password), /[^#{IUNRESERVED}|#{SUB_DELIMS}]/).encode(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})]/)
1298+
URI.encode(decoded, /[^(?:#{expr})]/).encode(Encoding::UTF_8)
12991299
end
13001300
end
13011301

spec/model_uri_spec.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -486,11 +486,6 @@
486486
expect(u1.canonicalize!.to_s).to eq u2.to_s
487487
expect(u1).to eq u2
488488
end
489-
it "#canonicalize does not fail with Encoding::CompatibilityError on weird IRIs" do
490-
u1 = RDF::URI "htЫtp://user:passoЫd@exaЫmple.com:8080/path ПУТЬ?queЫry=valЫue#fragmeЫnt"
491-
u2 = RDF::URI "ht%D0%ABtp://user:passoЫd@exaЫmple.com:8080/path%20ПУТЬ?queЫry=valЫue#fragmeЫnt"
492-
expect {u1.canonicalize.to_s.dup.force_encoding(u2.to_s.encoding)}.not_to raise_error
493-
end
494489
end
495490

496491
describe "#/" do

0 commit comments

Comments
 (0)