diff --git a/lib/w3c_validators/markup_validator.rb b/lib/w3c_validators/markup_validator.rb
index 95dcc91..323be00 100644
--- a/lib/w3c_validators/markup_validator.rb
+++ b/lib/w3c_validators/markup_validator.rb
@@ -1,15 +1,15 @@
module W3CValidators
class MarkupValidator < Validator
- MARKUP_VALIDATOR_URI = 'http://validator.w3.org/check'
+ MARKUP_VALIDATOR_URI = 'https://validator.w3.org/check'
# Create a new instance of the MarkupValidator.
#
# ==== Options
- # The +options+ hash allows you to set request parameters (see
- # http://validator.w3.org/docs/api.html#requestformat) quickly. Request
+ # The +options+ hash allows you to set request parameters (see
+ # http://validator.w3.org/docs/api.html#requestformat) quickly. Request
# parameters can also be set using set_charset!, set_debug! and set_doctype!.
#
- # You can pass in your own validator's URI (i.e.
+ # You can pass in your own validator's URI (i.e.
# MarkupValidator.new(:validator_uri => 'http://localhost/check')).
#
# See Validator#new for proxy server options.
@@ -22,14 +22,14 @@ def initialize(options = {})
end
super(options)
end
-
- # Specify the character encoding to use when parsing the document.
+
+ # Specify the character encoding to use when parsing the document.
#
- # When +only_as_fallback+ is +true+, the given encoding will only be
- # used as a fallback value, in case the +charset+ is absent or unrecognized.
+ # When +only_as_fallback+ is +true+, the given encoding will only be
+ # used as a fallback value, in case the +charset+ is absent or unrecognized.
#
- # +charset+ can be a string (e.g. set_charset!('utf-8')) or
- # a symbol (e.g. set_charset!(:utf_8)) from the
+ # +charset+ can be a string (e.g. set_charset!('utf-8')) or
+ # a symbol (e.g. set_charset!(:utf_8)) from the
# W3CValidators::CHARSETS hash.
#
# Has no effect when using validate_uri_quickly.
@@ -45,14 +45,14 @@ def set_charset!(charset, only_as_fallback = false)
@options[:fbc] = only_as_fallback
end
- # Specify the Document Type (+DOCTYPE+) to use when parsing the document.
+ # Specify the Document Type (+DOCTYPE+) to use when parsing the document.
#
- # When +only_as_fallback+ is +true+, the given document type will only be
- # used as a fallback value, in case the document's +DOCTYPE+ declaration
+ # When +only_as_fallback+ is +true+, the given document type will only be
+ # used as a fallback value, in case the document's +DOCTYPE+ declaration
# is missing or unrecognized.
#
- # +doctype+ can be a string (e.g. set_doctype!('HTML 3.2')) or
- # a symbol (e.g. set_doctype!(:html32)) from the
+ # +doctype+ can be a string (e.g. set_doctype!('HTML 3.2')) or
+ # a symbol (e.g. set_doctype!(:html32)) from the
# W3CValidators::DOCTYPES hash.
#
# Has no effect when using validate_uri_quickly.
@@ -68,11 +68,11 @@ def set_doctype!(doctype, only_as_fallback = false)
@options[:fbd] = only_as_fallback
end
- # When set the validator will output some extra debugging information on
- # the validated resource (such as HTTP headers) and validation process
+ # When set the validator will output some extra debugging information on
+ # the validated resource (such as HTTP headers) and validation process
# (such as parser used, parse mode, etc.).
#
- # Debugging information is stored in the Results +debug_messages+ hash.
+ # Debugging information is stored in the Results +debug_messages+ hash.
# Custom debugging messages can be set with Results#add_debug_message.
#
# Has no effect when using validate_uri_quickly.
@@ -100,7 +100,7 @@ def validate_uri_quickly(uri)
def validate_text(text)
return validate({:fragment => text}, false)
end
-
+
# Validate the markup of a local file.
#
# +file_path+ may be either the fully-expanded path to the file or
@@ -112,7 +112,7 @@ def validate_file(file_path)
src = file_path.read
else
src = read_local_file(file_path)
- end
+ end
return validate({:uploaded_file => src, :file_path => file_path}, false)
end
@@ -138,9 +138,9 @@ def validate(options, quick = false) # :nodoc:
# Perform sanity checks on request params
def get_request_options(options) # :nodoc:
options = @options.merge(options)
-
+
options[:output] = SOAP_OUTPUT_PARAM
-
+
unless options[:uri] or options[:uploaded_file] or options[:fragment]
raise ArgumentError, "an uri, uploaded file or fragment is required."
end
@@ -150,7 +150,7 @@ def get_request_options(options) # :nodoc:
if options[:uri] and not options[:uri].kind_of?(String)
options[:uri] = options[:uri].to_s
end
-
+
# Convert booleans to integers
[:fbc, :fbd, :verbose, :debug, :ss, :outline].each do |k|
if options.has_key?(k) and not options[k].kind_of?(Fixnum)
@@ -169,12 +169,12 @@ def get_request_options(options) # :nodoc:
# Returns W3CValidators::Results.
def parse_soap_response(response) # :nodoc:
doc = Nokogiri::XML(response)
- doc.remove_namespaces!
+ doc.remove_namespaces!
result_params = {}
- {:doctype => 'doctype', :uri => 'uri', :charset => 'charset',
- :checked_by => 'checkedby', :validity => 'validity'}.each do |local_key, remote_key|
+ {:doctype => 'doctype', :uri => 'uri', :charset => 'charset',
+ :checked_by => 'checkedby', :validity => 'validity'}.each do |local_key, remote_key|
if val = doc.css(remote_key)
result_params[local_key] = val.text
end
@@ -195,7 +195,7 @@ def parse_soap_response(response) # :nodoc:
doc.css("Fault Reason Text").each do |message|
results.add_message(:error, {:mesage => message.text})
end
-
+
doc.css("markupvalidationresponse debug").each do |debug|
results.add_debug_message(debug.attribute('name').value, debug.text)
end
@@ -212,7 +212,7 @@ def parse_soap_response(response) # :nodoc:
# Returns Results.
def parse_head_response(response, validated_uri = nil) # :nodoc:
validity = (response[HEAD_STATUS_HEADER].downcase == 'valid')
-
+
results = Results.new(:uri => validated_uri, :validity => validity)
# Fill the results with empty error messages so we can count them
@@ -222,6 +222,6 @@ def parse_head_response(response, validated_uri = nil) # :nodoc:
results
end
-
+
end
end
diff --git a/lib/w3c_validators/validator.rb b/lib/w3c_validators/validator.rb
index 451d38d..0c844ba 100644
--- a/lib/w3c_validators/validator.rb
+++ b/lib/w3c_validators/validator.rb
@@ -28,7 +28,7 @@ class Validator
# - +proxy_user+
# - +proxy_pass+
def initialize(options = {})
- @options = {:proxy_host => nil,
+ @options = {:proxy_host => nil,
:proxy_port => nil,
:proxy_user => nil,
:proxy_pass => nil}.merge(options)
@@ -45,8 +45,8 @@ def send_request(options, request_mode = :get, following_redirect = false, param
Net::HTTP::Proxy(@options[:proxy_host],
@options[:proxy_port],
- @options[:proxy_user],
- @options[:proxy_pass]).start(@validator_uri.host, @validator_uri.port) do |http|
+ @options[:proxy_user],
+ @options[:proxy_pass]).start(@validator_uri.host, @validator_uri.port) do |http|
case request_mode
when :head
@@ -54,9 +54,9 @@ def send_request(options, request_mode = :get, following_redirect = false, param
raise ArgumentError, "a URI must be provided for HEAD requests." unless options[:uri]
query = create_query_string_data(options)
response = http.request_head(@validator_uri.path + '?' + query)
- when :get
+ when :get
# send a GET request
- query = create_query_string_data(options)
+ query = create_query_string_data(options)
response = http.get(@validator_uri.path + '?' + query)
when :post
# send a multipart form request
@@ -69,10 +69,11 @@ def send_request(options, request_mode = :get, following_redirect = false, param
post = options
options = {}
end
-
+
qs = create_query_string_data(options)
-
+
query, boundary = create_multipart_data(post)
+ http.use_ssl = true if @validator_uri.port == 443
response = http.post2(@validator_uri.path + '?' + qs, query, "Content-type" => "multipart/form-data; boundary=" + boundary)
else
raise ArgumentError, "request_mode must be either :get, :head or :post"
@@ -110,7 +111,7 @@ def create_multipart_data(options) # :nodoc:
options.delete(:uploaded_file)
options.delete(:file_path)
end
-
+
if options[:content]
last_params << "Content-Disposition: form-data; name=\"#{CGI::escape('content')}\"\r\n" + "\r\n" + "#{options[:content]}\r\n"
end
@@ -124,14 +125,14 @@ def create_multipart_data(options) # :nodoc:
params = misc_params + last_params
- multipart_query = params.collect {|p| '--' + boundary + "\r\n" + p}.join('') + "--" + boundary + "--\r\n"
+ multipart_query = params.collect {|p| '--' + boundary + "\r\n" + p}.join('') + "--" + boundary + "--\r\n"
[multipart_query, boundary]
end
def create_query_string_data(options) # :nodoc:
qs = ''
- options.each do |key, value|
+ options.each do |key, value|
if value
qs += "#{key}=" + CGI::escape(value.to_s) + "&"
end
@@ -148,7 +149,7 @@ def read_local_file(file_path) # :nodoc:
# Big thanks to ara.t.howard and Joel VanderWerf on Ruby-Talk for the exception handling help.
#++
def handle_exception(e, msg = '') # :nodoc:
- case e
+ case e
when Net::HTTPServerException, SocketError
msg = "unable to connect to the validator at #{@validator_uri} (response was #{e.message})."
raise ValidatorUnavailable, msg, caller
@@ -182,6 +183,6 @@ def handle_exception(e, msg = '') # :nodoc:
exit_status(( exit_failure )) if exit_status == exit_success
exit_status(( Integer(exit_status) rescue(exit_status ? 0 : 1) ))
exit exit_status
- end
+ end
end
end