sqt 1.2.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/sqt.rb +28 -11
  2. metadata +1 -1
data/lib/sqt.rb CHANGED
@@ -10,6 +10,7 @@ module SQT
10
10
  require 'nokogiri'
11
11
 
12
12
  require 'colorize'
13
+ require 'uri'
13
14
 
14
15
  class Sqt
15
16
 
@@ -37,25 +38,41 @@ module SQT
37
38
 
38
39
  # Curl with depth
39
40
  def self.sarbotteCurlWithDepth(url, depth, result)
41
+ urlUrl = URI(url)
40
42
  http = Curl.get(url)
41
43
  file = http.body_str
42
44
  xmlFile = Nokogiri::HTML(file)
45
+ allowedScheme = ['http', 'https']
46
+ if !(result.any? {|sqr| URI(sqr[:uri]).path.gsub(/\/$/, '') == urlUrl.path.gsub(/\/$/, '') })
47
+ result.push Sqt.buildResult(url, file)
48
+ end
43
49
  if depth > 0
44
50
  xmlFile.search('//a').each do |foundLink|
45
- if foundLink['href'] =~ /^\//
46
- toVisit = url + foundLink['href']
47
- else
48
- toVisit = foundLink['href']
49
- end
50
- if !(toVisit =~ /^http(s)?:\/\//).nil? && !result.any? {|sqr| sqr[:uri] == toVisit || sqr[:uri] == toVisit + '/' || sqr[:uri] + '/' == toVisit }
51
- d = sarbotteCurlWithDepth(toVisit, depth - 1, result)
52
- result = d if !d.nil?
51
+ begin
52
+ if foundLink['href'] =~ /^\//
53
+ toVisit = url.gsub(/\/$/, '') + foundLink['href']
54
+ else
55
+ toVisit = foundLink['href']
56
+ end
57
+ puts toVisit
58
+ if !(toVisit =~ /^\s*$/)
59
+ toVisitUrl = URI(toVisit)
60
+ result.any? do |sqr|
61
+ URI(sqr[:uri]).path.gsub(/\/$/, '') == toVisitUrl.path.gsub(/\/$/, '')
62
+ end
63
+ if urlUrl.host == toVisitUrl.host && allowedScheme.include?(toVisitUrl.scheme) && !result.any? { |sqr| URI(sqr[:uri]).path.gsub(/\/$/, '') == toVisitUrl.path.gsub(/\/$/, '') }
64
+ d = sarbotteCurlWithDepth(toVisit, depth - 1, result)
65
+ result = d if !d.nil?
66
+ end
67
+ end
68
+ rescue
69
+ puts "exception"
53
70
  end
54
71
  end
55
72
  end
56
- if !(result.any? {|sqr| sqr[:uri] == url || sqr[:uri] == url + '/' || sqr[:uri] + '/' == url })
57
- result.push Sqt.buildResult(url, file)
58
- end
73
+
74
+ result
75
+
59
76
  end
60
77
 
61
78
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sqt
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: