From 78cd4e2e359f5e51065543e956c0b74626b453e2 Mon Sep 17 00:00:00 2001 From: Anton Maminov Date: Mon, 29 Jul 2024 16:17:54 +0300 Subject: [PATCH 1/2] fix Crest::Resource#concat_urls --- src/crest.cr | 1 - src/crest/resource.cr | 7 +++++-- src/ext/uri.cr | 14 -------------- 3 files changed, 5 insertions(+), 17 deletions(-) delete mode 100644 src/ext/uri.cr 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 From c3013fe0f44cec18275970e4b83190f70c18a56f Mon Sep 17 00:00:00 2001 From: Anton Maminov Date: Mon, 29 Jul 2024 16:20:27 +0300 Subject: [PATCH 2/2] Update CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) 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)