diff --git a/CHANGELOG.md b/CHANGELOG.md index 66c39632..29984d2b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## [...] +- Fix Crest::Resource#concat_urls [#229](https://github.com/mamantoha/crest/pull/229) + ## [1.4.0][] (2024-08-26) - Fix typo in README.md by @kojix2 in [#223](https://github.com/mamantoha/crest/pull/223) diff --git a/src/crest.cr b/src/crest.cr index 0569729c..2816c4a9 100644 --- a/src/crest.cr +++ b/src/crest.cr @@ -8,7 +8,6 @@ require "./ext/io" require "./ext/int" require "./ext/float" require "./ext/http/cookie" -require "./ext/uri" # This module's static methods are the entry point for using the Crest client. # diff --git a/src/crest/resource.cr b/src/crest/resource.cr index d9f9dc4d..9aed93ad 100644 --- a/src/crest/resource.cr +++ b/src/crest/resource.cr @@ -232,8 +232,11 @@ module Crest other end - private def concat_urls(url : String, suburl : String) : String - URI.join(url, URI.parse(suburl)).to_s + private def concat_urls(base_url : String, path : String) : String + base_url = base_url.ends_with?('/') ? base_url[...-1] : base_url + path = path.starts_with?('/') ? path[1..] : path + + [base_url, path].join('/') end end end diff --git a/src/ext/uri.cr b/src/ext/uri.cr deleted file mode 100644 index 09b1be2c..00000000 --- a/src/ext/uri.cr +++ /dev/null @@ -1,14 +0,0 @@ -# :nodoc: -# https://github.com/crystal-lang/crystal/issues/13114 -class URI - class BadURIError < Exception - end - - def self.join(*args) - url = args[1..-1].reduce(URI.parse(args[0])) { |a, e| a.resolve(e) } - - raise BadURIError.new("both URI are relative") if url.relative? - - url - end -end