lib/ronin/url.rb in ronin-1.1.0.rc3 vs lib/ronin/url.rb in ronin-1.1.0
- old
+ new
@@ -184,11 +184,11 @@
# @since 1.0.0
#
# @api public
#
def self.query_param(name)
- all('query_params.name' => name)
+ all('query_params.name.name' => name)
end
#
# Search for all URLs with a given query param value.
#
@@ -221,35 +221,31 @@
#
def self.[](url)
return super(url) if url.kind_of?(Integer)
# optionally parse the URL
- unless url.kind_of?(::URI)
- url = ::URI.parse(url.to_s)
- end
+ url = ::URI.parse(url.to_s) unless url.kind_of?(::URI)
- port = if url.port
- {:number => url.port}
- end
-
- path = normalized_path(url)
- fragment = url.fragment
-
# create the initial query
query = all(
- :scheme => {:name => url.scheme},
- :host_name => {:address => url.host},
- :port => port,
- :path => path,
- :fragment => fragment
+ 'scheme.name' => url.scheme,
+ 'host_name.address' => url.host,
+ :path => normalized_path(url),
+ :fragment => url.fragment
)
+ if url.port
+ # query the port
+ query = query.all('port.number' => url.port)
+ end
+
if url.query
# add the query params to the query
URI::QueryParams.parse(url.query).each do |name,value|
query = query.all(
- :query_params => {:name => name, :value => value}
+ 'query_params.name.name' => name,
+ 'query_params.value' => value
)
end
end
return query.first
@@ -268,28 +264,28 @@
#
# @api public
#
def self.from(uri)
# find or create the URL scheme, host_name and port
- scheme = self.scheme.model.first_or_new(:name => uri.scheme)
- host_name = self.host_name.model.first_or_new(:address => uri.host)
+ scheme = URLScheme.first_or_new(:name => uri.scheme)
+ host_name = HostName.first_or_new(:address => uri.host)
port = if uri.port
- self.port.model.first_or_new(:number => uri.port)
+ TCPPort.first_or_new(:number => uri.port)
end
path = normalized_path(uri)
fragment = uri.fragment
query_params = []
if uri.respond_to?(:query_params)
# find or create the URL query params
uri.query_params.each do |name,value|
- query_params << self.query_params.model.first_or_new(
- :name => name,
+ query_params << {
+ :name => URLQueryParamName.first_or_new(:name => name),
:value => value
- )
+ }
end
end
# find or create the URL
return first_or_new(
@@ -384,10 +380,13 @@
#
def query_string=(query)
self.query_params.clear
URI::QueryParams.parse(query).each do |name,value|
- self.query_params.new(:name => name, :value => value)
+ self.query_params.new(
+ :name => URLQueryParamName.first_or_new(:name => name),
+ :value => value
+ )
end
return query
end