Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
cocoapods
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gengmeiios
cocoapods
Commits
dc49ae52
Commit
dc49ae52
authored
Apr 13, 2014
by
Boris Bügling
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2027 from CocoaPods/feature-allow-homepage-redirects
Feature allow homepage redirects
parents
d3b515b3
ab2de1c5
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
1 deletion
+53
-1
CHANGELOG.md
CHANGELOG.md
+6
-0
validator.rb
lib/cocoapods/validator.rb
+20
-1
validator_spec.rb
spec/unit/validator_spec.rb
+27
-0
No files found.
CHANGELOG.md
View file @
dc49ae52
...
...
@@ -33,6 +33,12 @@ To install or update CocoaPods see this [guide](http://docs.cocoapods.org/guides
[
Samuel Ford
](
https://github.com/samuelwford
)
[
#1042
](
https://github.com/CocoaPods/CocoaPods/issues/1042
)
##### Bug Fixes
*
Support HTTP redirects when linting homepage and screenshots.
[
Boris Bügling
](
https://github.com/neonichu
)
[
#2027
](
https://github.com/CocoaPods/CocoaPods/pull/2027
)
## 0.31.1
[
CocoaPods
](
https://github.com/CocoaPods/CocoaPods/compare/0.31.1...0.31.0
)
•
[
CocoaPods-Core
](
https://github.com/CocoaPods/Core/compare/0.31.1...0.31.0
)
...
...
lib/cocoapods/validator.rb
View file @
dc49ae52
...
...
@@ -223,13 +223,32 @@ module Pod
attr_accessor
:consumer
attr_accessor
:subspec_name
MAX_HTTP_REDIRECTS
=
3
# Performs validation of a URL
#
def
validate_url
(
url
)
require
'rest'
begin
redirects
=
0
resp
=
nil
loop
do
resp
=
::
REST
.
head
(
url
)
if
resp
.
status_code
==
405
resp
=
::
REST
.
get
(
url
)
end
if
[
301
,
302
,
303
,
307
,
308
].
include?
resp
.
status_code
url
=
resp
.
headers
[
'location'
].
first
redirects
+=
1
else
break
end
break
unless
redirects
<
MAX_HTTP_REDIRECTS
end
rescue
warning
"There was a problem validating the URL
#{
url
}
."
resp
=
nil
...
...
@@ -253,7 +272,7 @@ module Pod
# Performs validation related to the `screenshots` attribute.
#
def
validate_screenshots
(
spec
)
spec
.
screenshots
.
each
do
|
screenshot
|
spec
.
screenshots
.
compact
.
each
do
|
screenshot
|
request
=
validate_url
(
screenshot
)
if
request
&&
!
(
request
.
headers
[
'content-type'
]
&&
request
.
headers
[
'content-type'
].
first
=~
/image\/.*/i
)
warning
"The screenshot
#{
screenshot
}
is not a valid image."
...
...
spec/unit/validator_spec.rb
View file @
dc49ae52
...
...
@@ -109,6 +109,33 @@ module Pod
@sut
.
validate
@sut
.
results
.
map
(
&
:to_s
).
first
.
should
.
match
/There was a problem validating the URL/
end
it
"does not fail if the homepage redirects"
do
WebMock
::
API
.
stub_request
(
:head
,
/redirect/
).
to_return
(
:status
=>
301
,
:headers
=>
{
'Location'
=>
'http://banana-corp.local/found/'
}
)
WebMock
::
API
.
stub_request
(
:head
,
/found/
).
to_return
(
:status
=>
200
)
Specification
.
any_instance
.
stubs
(
:homepage
).
returns
(
'http://banana-corp.local/redirect/'
)
@sut
.
validate
@sut
.
results
.
length
.
should
.
equal
0
end
it
"does not fail if the homepage does not support HEAD"
do
WebMock
::
API
.
stub_request
(
:head
,
/page/
).
to_return
(
:status
=>
405
)
WebMock
::
API
.
stub_request
(
:get
,
/page/
).
to_return
(
:status
=>
200
)
Specification
.
any_instance
.
stubs
(
:homepage
).
returns
(
'http://banana-corp.local/page/'
)
@sut
.
validate
@sut
.
results
.
length
.
should
.
equal
0
end
it
"does not follow redirects infinitely"
do
WebMock
::
API
.
stub_request
(
:head
,
/redirect/
).
to_return
(
:status
=>
301
,
:headers
=>
{
'Location'
=>
'http://banana-corp.local/redirect/'
}
)
Specification
.
any_instance
.
stubs
(
:homepage
).
returns
(
'http://banana-corp.local/redirect/'
)
@sut
.
validate
@sut
.
results
.
map
(
&
:to_s
).
first
.
should
.
match
/The URL \(.*\) is not reachable/
end
end
describe
"Screenshot validation"
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment