normalize_url 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -0
- data/lib/normalize_url/normalizer.rb +11 -2
- data/lib/normalize_url/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 55028bf73f8d7ab29f8b6eed85f5af3645e2b1a5
|
4
|
+
data.tar.gz: cc45799207ab2006d5d145441897a621ccc2fc71
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a394f7e5d7f4de0d0dd5b5331efc30de7872aae59e5c695b14e957bf4cf3f5effbf1d451a39894c63b09813db9e4c75e59f954c17ede921910c90986bfd951f7
|
7
|
+
data.tar.gz: 16a6d91566ce59953ed3a3ed063ff843320826c45cf5a9a7742172dbf982a02f1756354a5c984fe85ab8b9acc781a968146238441feeaa0e61030cac8809ac8b
|
data/README.md
CHANGED
@@ -10,11 +10,13 @@ resource should look exactly the same.
|
|
10
10
|
For example:
|
11
11
|
|
12
12
|
- `http://example.com/products`
|
13
|
+
- `HTTP://EXAMPLE.COM/products/`
|
13
14
|
- `http://example.com/products/`
|
14
15
|
- `http://example.com/foo/../products`
|
15
16
|
- `http://example.com/products#comments-section`
|
16
17
|
- `http://example.com//products/`
|
17
18
|
- `http://example.com/products?`
|
19
|
+
- `http://example.com/products?utm_source=whatever`
|
18
20
|
|
19
21
|
will all become `http://example.com/products` after normalization.
|
20
22
|
|
@@ -71,6 +73,12 @@ NormalizeUrl.process("http://example.com/foo/", remove_trailing_slash: false) #
|
|
71
73
|
|
72
74
|
`http://example.com/foo#bar` -> `http://example.com/foo`
|
73
75
|
|
76
|
+
- Remove tracking. Option `:remove_tracking`.
|
77
|
+
|
78
|
+
Example:
|
79
|
+
|
80
|
+
`http://example.com/?utm_source=whatever` -> `http://example.com/`
|
81
|
+
|
74
82
|
- Sort query string. Option `:sort_query`.
|
75
83
|
|
76
84
|
Example:
|
@@ -15,7 +15,7 @@ module NormalizeUrl
|
|
15
15
|
awesm
|
16
16
|
xtor
|
17
17
|
PHPSESSID
|
18
|
-
].to_set
|
18
|
+
].to_set.freeze
|
19
19
|
|
20
20
|
def initialize(original_uri, options={})
|
21
21
|
@uri = Addressable::URI.parse(original_uri).normalize
|
@@ -31,6 +31,7 @@ module NormalizeUrl
|
|
31
31
|
process :remove_repeating_slashes
|
32
32
|
process :remove_hash
|
33
33
|
process :remove_tracking
|
34
|
+
process :remove_params
|
34
35
|
process :sort_query
|
35
36
|
uri.to_s
|
36
37
|
end
|
@@ -62,9 +63,17 @@ module NormalizeUrl
|
|
62
63
|
end
|
63
64
|
|
64
65
|
def process_remove_tracking
|
66
|
+
remove_params TRACKING_QUERY_PARAMS
|
67
|
+
end
|
68
|
+
|
69
|
+
def process_remove_params
|
70
|
+
remove_params Array(@options.fetch(:remove_params, nil)).map(&:to_s)
|
71
|
+
end
|
72
|
+
|
73
|
+
def remove_params(params)
|
65
74
|
return unless uri.query_values
|
66
75
|
original = uri.query_values
|
67
|
-
cleaned = original.reject{ |key, _|
|
76
|
+
cleaned = original.reject{ |key, _| params.include?(key) }
|
68
77
|
|
69
78
|
if cleaned.empty?
|
70
79
|
uri.query_values = nil
|