truncator 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -7
- data/Gemfile +1 -1
- data/lib/truncator/extended_uri.rb +7 -3
- data/lib/truncator/url_parser.rb +3 -3
- data/lib/truncator/version.rb +1 -1
- data/spec/url_parser_spec.rb +0 -10
- metadata +15 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e5276cca37ceaa33ed7d3cbdb991a55a63dc1c5e
|
4
|
+
data.tar.gz: 66bc5849518bce29397004be96990e33c5ef0106
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f3bacbb6ff2f4aef0cb8c268af58e04ec30e5b6f8b572039ae175bfb355ff9471d7f31216f43d967c2e8f877adb32f81f20106d4b4a7194a55e2f51e2eed9d3
|
7
|
+
data.tar.gz: 4b681896df0dcf909040b6fb9e2a6e512a749b6660dbe911c295baa9c730cbb69ceda4f82990e1d96dae551fbd4d17036726ac74bbec5d74aa5d95c2f6484571
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -30,14 +30,14 @@ module Truncator
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def query_parameters
|
33
|
-
if
|
34
|
-
URI.decode_www_form(self.query)
|
35
|
-
else
|
33
|
+
if query_bug_in_ruby?
|
36
34
|
begin
|
37
35
|
URI.decode_www_form(self.query)
|
38
36
|
rescue ArgumentError # fixed in ruby 2.1.0 r40460
|
39
37
|
raise QueryParamWithoutValueError
|
40
38
|
end
|
39
|
+
else
|
40
|
+
URI.decode_www_form(self.query)
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
@@ -62,6 +62,10 @@ module Truncator
|
|
62
62
|
port = self.port
|
63
63
|
self.to_s.include? ":#{port}"
|
64
64
|
end
|
65
|
+
|
66
|
+
def query_bug_in_ruby?
|
67
|
+
Gem::Version.new(RUBY_VERSION) <= Gem::Version.new('2.1.0')
|
68
|
+
end
|
65
69
|
end
|
66
70
|
end
|
67
71
|
end
|
data/lib/truncator/url_parser.rb
CHANGED
@@ -16,7 +16,7 @@ module Truncator
|
|
16
16
|
return uri.truncate(truncation_length)
|
17
17
|
end
|
18
18
|
|
19
|
-
if
|
19
|
+
if !uri.ordinary_hostname?
|
20
20
|
if uri.query
|
21
21
|
uri.query_parameters = [uri.query_parameters.first]
|
22
22
|
return uri.to_s + SEPARATOR
|
@@ -27,12 +27,12 @@ module Truncator
|
|
27
27
|
|
28
28
|
return uri.special_format if uri.special_format.valid_length?(truncation_length)
|
29
29
|
|
30
|
-
if uri.path_blank?
|
30
|
+
if uri.path_blank? && !uri.query
|
31
31
|
return uri.special_format.truncate!(truncation_length)
|
32
32
|
end
|
33
33
|
|
34
34
|
if uri.query
|
35
|
-
|
35
|
+
return uri.special_format.truncate!(truncation_length)
|
36
36
|
else
|
37
37
|
if uri.host.valid_length?(truncation_length)
|
38
38
|
result = truncate_by_shortest(uri, truncation_length)
|
data/lib/truncator/version.rb
CHANGED
data/spec/url_parser_spec.rb
CHANGED
@@ -2,9 +2,7 @@ require 'spec_helper'
|
|
2
2
|
require 'truncator'
|
3
3
|
|
4
4
|
describe Truncator::UrlParser do
|
5
|
-
|
6
5
|
describe ".shorten_url" do
|
7
|
-
|
8
6
|
context "when no truncation length is specified, the URL is too long, has sublevels, but no query params" do
|
9
7
|
let(:shortened) { Truncator::UrlParser.shorten_url "http://www.foo.com/this/is/a/b/c/d/e/f/string.html" }
|
10
8
|
|
@@ -185,13 +183,5 @@ describe Truncator::UrlParser do
|
|
185
183
|
end
|
186
184
|
end
|
187
185
|
end
|
188
|
-
|
189
|
-
context 'when URL contains query param with no value' do
|
190
|
-
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' }
|
191
|
-
|
192
|
-
it 'should just perform a basic truncation' do
|
193
|
-
Truncator::UrlParser.shorten_url(missing_param_value).should == 'https://npiregistry.cms.hhs.gov/NPPESRe...'
|
194
|
-
end
|
195
|
-
end
|
196
186
|
end
|
197
187
|
end
|
metadata
CHANGED
@@ -1,69 +1,69 @@
|
|
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.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- freemanoid
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-07-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '1.3'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.3'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - ~>
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '2.13'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - ~>
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '2.13'
|
69
69
|
description: url truncator
|
@@ -73,8 +73,8 @@ executables: []
|
|
73
73
|
extensions: []
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
|
-
- .gitignore
|
77
|
-
- .travis.yml
|
76
|
+
- ".gitignore"
|
77
|
+
- ".travis.yml"
|
78
78
|
- Gemfile
|
79
79
|
- LICENSE.txt
|
80
80
|
- README.md
|
@@ -98,17 +98,17 @@ require_paths:
|
|
98
98
|
- lib
|
99
99
|
required_ruby_version: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- -
|
101
|
+
- - ">="
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: 2.0.0
|
104
104
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
105
|
requirements:
|
106
|
-
- -
|
106
|
+
- - ">="
|
107
107
|
- !ruby/object:Gem::Version
|
108
108
|
version: '0'
|
109
109
|
requirements: []
|
110
110
|
rubyforge_project:
|
111
|
-
rubygems_version: 2.
|
111
|
+
rubygems_version: 2.4.8
|
112
112
|
signing_key:
|
113
113
|
specification_version: 4
|
114
114
|
summary: Truncate urls as much as possible
|