truncator 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7f1d135f3a6f772a04837fdbc7c90cc8c34c2a3c
4
- data.tar.gz: f0ecab4c3cf49bf50c27e97b34ce469a65c465d2
3
+ metadata.gz: 664e2bb87bc33032c0dd931d417c22d87fc0f241
4
+ data.tar.gz: e05bfc012e31afaf14ebfddde0776f6a532020e2
5
5
  SHA512:
6
- metadata.gz: 642c711d588aef93847b2bd17e2c17e2c272ab7f5c6b80839d66407b8c67800d18fd3b7f667ea0c950ea541e31577f9148b093e00dea71a4b08b71860530c553
7
- data.tar.gz: b4c0897e7c97f91008886f3851627c9a3ef865c3781b2a1ccfa133201f4c2c161d5e3d0bb20375cbb6d2dafbd772359536061749fe68d57111a3c50683ccf6c8
6
+ metadata.gz: 80c8cd8755b1d0bda2c98ebbaf80522c8196d851121c4ef7b9e51c2d3986b5a1abf28b984dbb262efac38bcd224dcc9394f23c70c92b5e620fde3282c0f760fa
7
+ data.tar.gz: ab977d4f710eedffc3b9502338f7a40b8ff8a39d601e7d9ec53299ce7edb0ea575d764c055bc15a84ba75bd5281580fe33e0234a4b04c2abd9ce090a16e10dfc
@@ -9,7 +9,11 @@ module Truncator
9
9
  String.separator = SEPARATOR
10
10
 
11
11
  def shorten_url(uri, truncation_length = 42)
12
- uri = URI(uri)
12
+ begin
13
+ uri = URI(uri)
14
+ rescue URI::InvalidURIError
15
+ return uri.truncate(truncation_length)
16
+ end
13
17
 
14
18
  if not uri.ordinary_hostname?
15
19
  if uri.query
@@ -1,3 +1,3 @@
1
1
  module Truncator
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -9,7 +9,6 @@ describe Truncator::UrlParser do
9
9
  let(:shortened) { Truncator::UrlParser.shorten_url "http://www.foo.com/this/is/a/b/c/d/e/f/string.html" }
10
10
 
11
11
  it "should default to truncate at 42 characters" do
12
- # shortened.should == "www.foo.com/this/is/a/.../e/f/string.html"
13
12
  shortened.length.should <= 42
14
13
  end
15
14
  end
@@ -61,24 +60,8 @@ describe Truncator::UrlParser do
61
60
  end
62
61
  end
63
62
 
64
- # it "should replace path segments with ellipses to shorten the path as much as necessary for various lengths", focus: true do
65
- # url = "http://www.foo.com/this/goes/on/and/on/and/on/with/XXX.html"
66
- # Truncator::UrlParser.shorten_url(url, 24).should == "www.foo.com/.../XXX.html"
67
- # 32.upto(33) { |n| Truncator::UrlParser.shorten_url(url, n).should == "www.foo.com/.../on/with/XXX.html" }
68
- # 35.upto(39) { |n| Truncator::UrlParser.shorten_url(url, n).should == "www.foo.com/this/.../with/XXX.html" }
69
- # 40.upto(42) { |n| Truncator::UrlParser.shorten_url(url, n).should == "www.foo.com/this/goes/.../with/XXX.html" }
70
- # 43.upto(45) { |n| Truncator::UrlParser.shorten_url(url, n).should == "www.foo.com/this/goes/.../on/with/XXX.html" }
71
- # end
72
63
  end
73
64
 
74
- # context "when URL is too long and has at least one sublevel specified as well as a query parameter" do
75
- # let(:shortened) { Truncator::UrlParser.shorten_url("http://www.foo.com/this/goes/on/and/on/and/on/and/on/and/ends/with/XXXX.html?q=1&a=2&b=3", 50) }
76
-
77
- # it "should replace path segments with ellipses to shorten the path as much as necessary, and show only the first param, followed by ellipses" do
78
- # shortened.should == "www.foo.com/this/goes/.../with/XXXX.html?q=1..."
79
- # end
80
- # end
81
-
82
65
  context "when URL is more than 30 chars long and does not have at least one sublevel specified" do
83
66
  let(:shortened) { Truncator::UrlParser.shorten_url("http://www.mass.gov/?pageID=trepressrelease&L=4&L0=Home&L1=Media+%26+Publications&L2=Treasury+Press+Releases&L3=2006&sid=Ctre&b=pressrelease&f=2006_032706&csid=Ctre", 30) }
84
67
 
@@ -172,6 +155,13 @@ describe Truncator::UrlParser do
172
155
  end
173
156
  end
174
157
  end
175
- end
176
158
 
159
+ context 'when URL is invalid URL' do
160
+ let(:dangerous_url) { "http://www.first.army.mil/family/contentdisplayFAFP.asp?ContentID=133&SiteID=\"><script>alert(String.fromCharCode(88,83,83))</script>" }
161
+
162
+ it 'should just perform a basic truncation' do
163
+ Truncator::UrlParser.shorten_url(dangerous_url, 30).should == 'http://www.first.army.mil/f...'
164
+ end
165
+ end
166
+ end
177
167
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: truncator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - freemanoid