Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String Manipulation and Comparison Operations #341

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/http/content_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ def parse(str)

# :nodoc:
def mime_type(str)
md = str.to_s.match MIME_TYPE_RE
md && md[1].to_s.strip.downcase
m = str.to_s[MIME_TYPE_RE, 1]
m && m.strip.downcase
end

# :nodoc:
def charset(str)
md = str.to_s.match CHARSET_RE
md && md[1].to_s.strip.gsub(/^"|"$/, "")
m = str.to_s[CHARSET_RE, 1]
m && m.strip.delete('"')
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/http/redirector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ def perform(request, response)
# Check if we reached max amount of redirect hops
# @return [Boolean]
def too_many_hops?
1 <= @max_hops && @max_hops < @visited.count
@max_hops > 0 && @visited.count > @max_hops
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think @visited.size or @visited.length would be more descriptive here.

end

# Check if we got into an endless loop
# @return [Boolean]
def endless_loop?
2 <= @visited.count(@visited.last)
@visited.count(@visited.last) > 1
end

# Redirect policy for follow
Expand All @@ -90,7 +90,7 @@ def redirect_to(uri)
verb = :get
end

verb = :get if !SEE_OTHER_ALLOWED_VERBS.include?(verb) && 303 == code
verb = :get if !SEE_OTHER_ALLOWED_VERBS.include?(verb) && code == 303

@request.redirect(uri, verb)
end
Expand Down
4 changes: 2 additions & 2 deletions lib/http/response/status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def coerce(object)
# @param [#to_s] str
# @return [Symbol]
def symbolize(str)
str.to_s.downcase.tr("-", " ").gsub(/[^a-z ]/, "").gsub(/\s+/, "_").to_sym
str.to_s.downcase.tr("- ", "_").delete("^a-z_").to_sym
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[1] pry(main)> "Bad  request".downcase.tr("- ", "_").delete("^a-z_").to_sym
=> :bad__request
[2] pry(main)> "Bad  request".downcase.tr("-", " ").gsub(/[^a-z ]/, "").gsub(/\s+/, "_").to_sym
=> :bad_request

end
end

Expand Down Expand Up @@ -132,7 +132,7 @@ def inspect
SYMBOLS.each do |code, symbol|
class_eval <<-RUBY, __FILE__, __LINE__
def #{symbol}? # def bad_request?
#{code} == code # 400 == code
code == #{code} # code == 400
end # end
RUBY
end
Expand Down