truncator 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/truncator/extended_uri.rb +7 -1
- data/lib/truncator/url_parser.rb +4 -0
- data/lib/truncator/version.rb +1 -1
- data/spec/url_parser_spec.rb +9 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 569306c1d30040a36691edb14d10dd202edd90ae
|
4
|
+
data.tar.gz: 9e8a3cca376177beb1ca8bfeb4ee17776334ff0e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 783a55829c621c019b81ec3b0af3a9b1c696608498bed06c3418bc0137474458e962c9765542729b8479620c48518ca8cfd8ba44e13c4988c86e989548fc94d0
|
7
|
+
data.tar.gz: f53daacef940d209fbf99866fc4df388918507f8eb5642b855904776cb90a5054bb091cc4ee99a860648b151dbcf0b09ae0861f2d2a427dd720a774a0f5d4f7a
|
@@ -2,6 +2,8 @@ require 'uri'
|
|
2
2
|
|
3
3
|
module Truncator
|
4
4
|
module ExtendedURI
|
5
|
+
class QueryParamWithoutValueError < URI::Error; end
|
6
|
+
|
5
7
|
refine URI::Generic do
|
6
8
|
def ordinary_hostname?
|
7
9
|
if %w(https ftp).include?(self.scheme) || self.userinfo || self.port_defined?
|
@@ -28,7 +30,11 @@ module Truncator
|
|
28
30
|
end
|
29
31
|
|
30
32
|
def query_parameters
|
31
|
-
|
33
|
+
begin
|
34
|
+
URI.decode_www_form(self.query)
|
35
|
+
rescue ArgumentError # fixed in ruby 2.1.0 r40460
|
36
|
+
raise QueryParamWithoutValueError
|
37
|
+
end
|
32
38
|
end
|
33
39
|
|
34
40
|
def query_parameters=(params)
|
data/lib/truncator/url_parser.rb
CHANGED
@@ -12,6 +12,7 @@ module Truncator
|
|
12
12
|
begin
|
13
13
|
uri = URI(uri)
|
14
14
|
rescue URI::InvalidURIError
|
15
|
+
uri.sub!(/\Ahttp:\/\//, '') # remove http protocol
|
15
16
|
return uri.truncate(truncation_length)
|
16
17
|
end
|
17
18
|
|
@@ -46,6 +47,9 @@ module Truncator
|
|
46
47
|
end
|
47
48
|
|
48
49
|
uri.special_format
|
50
|
+
|
51
|
+
rescue Truncator::ExtendedURI::QueryParamWithoutValueError
|
52
|
+
return uri.to_s.truncate(truncation_length)
|
49
53
|
end
|
50
54
|
|
51
55
|
private
|
data/lib/truncator/version.rb
CHANGED
data/spec/url_parser_spec.rb
CHANGED
@@ -173,8 +173,16 @@ describe Truncator::UrlParser do
|
|
173
173
|
context 'when URL is invalid URL' do
|
174
174
|
let(:dangerous_url) { "http://www.first.army.mil/family/contentdisplayFAFP.asp?ContentID=133&SiteID=\"><script>alert(String.fromCharCode(88,83,83))</script>" }
|
175
175
|
|
176
|
+
it 'should just perform a basic truncation after removing http://' do
|
177
|
+
Truncator::UrlParser.shorten_url(dangerous_url, 30).should == 'www.first.army.mil/family/c...'
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
context 'when URL contains query param with no value' do
|
182
|
+
let(:missing_param_value) { 'https://npiregistry.cms.hhs.gov/NPPESRegistry/DisplayProviderDetails.do?searchNpi=1629006051&city=&firstName=&orgName=&searchType=ind&state=&npi=1629006051&orgDba=&lastName=&zip' }
|
183
|
+
|
176
184
|
it 'should just perform a basic truncation' do
|
177
|
-
Truncator::UrlParser.shorten_url(
|
185
|
+
Truncator::UrlParser.shorten_url(missing_param_value).should == 'https://npiregistry.cms.hhs.gov/NPPESRe...'
|
178
186
|
end
|
179
187
|
end
|
180
188
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: truncator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- freemanoid
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-11-
|
11
|
+
date: 2013-11-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|