Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

If domain included a trailing slash Packagist would reject the notifi…

…cation

If `http://packagist.org/` was entered, the URL being generated
was `http://packagist.org//api/github` which would fail as it
is not a valid route.

Fixed by replacing the strip command with lstrip followed by
a regex to replace any trailing slashes or whitespace with
nothing.

Added tests to ensure it is doing what is expected.

Reordered fields.
  • Loading branch information...
commit 35c8851ab8d603947cdde1c933b9ad60dd65fb55 1 parent b6e7938
@simensen simensen authored
Showing with 40 additions and 2 deletions.
  1. +2 −2 services/packagist.rb
  2. +38 −0 test/packagist_test.rb
View
4 services/packagist.rb
@@ -1,5 +1,5 @@
class Service::Packagist < Service
- string :domain, :user, :token
+ string :user, :token, :domain
white_list :domain, :user
def receive_push
@@ -38,7 +38,7 @@ def full_domain
'http://packagist.org'
else
data['domain']
- end.strip
+ end.lstrip.sub(/[\/\s]+$/,'')
end
def domain_parts
View
38 test/packagist_test.rb
@@ -65,6 +65,44 @@ def test_handles_blank_strings_without_errors
assert_equal 'http', svc.scheme
end
+ def test_detects_http_url
+ data = {
+ 'domain' => 'http://packagist.example.com/'
+ }
+
+ svc = service(data, payload)
+ assert_equal 'packagist.example.com', svc.domain
+ assert_equal 'http', svc.scheme
+ end
+
+ def test_detects_https_url
+ data = {
+ 'domain' => 'https://packagist.example.com/'
+ }
+
+ svc = service(data, payload)
+ assert_equal 'packagist.example.com', svc.domain
+ assert_equal 'https', svc.scheme
+ end
+
+ def test_strips_trailing_slash
+ data = {
+ 'domain' => 'packagist.example.com/ '
+ }
+
+ svc = service(data, payload)
+ assert_equal 'packagist.example.com', svc.domain
+ end
+
+ def test_strips_trailing_slash_deep_path
+ data = {
+ 'domain' => 'packagist.example.com/path/to/subdirectory/ '
+ }
+
+ svc = service(data, payload)
+ assert_equal 'packagist.example.com/path/to/subdirectory', svc.domain
+ end
+
def test_infers_user_from_repo_data
svc = service(data.reject{|key,v| key == 'user'}, payload)
assert_equal "mojombo", svc.user
Please sign in to comment.
Something went wrong with that request. Please try again.