-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathurl-sanitize.rb
More file actions
53 lines (46 loc) · 2.07 KB
/
url-sanitize.rb
File metadata and controls
53 lines (46 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
require "json"
class UrlSanitize < Formula
desc "Remove tracking parameters and unwrap tracking redirects from URLs"
homepage "https://github.com/antonio-orionus/url-sanitize"
version "0.1.4"
license "MIT"
if OS.mac?
if Hardware::CPU.arm?
url "https://github.com/antonio-orionus/url-sanitize/releases/download/v#{version}/url-sanitize-aarch64-apple-darwin.tar.gz"
sha256 "dd705697a1a1ea883c438e465a188fac27f13212f4ba42d69c20e7b4a8785c0e"
elsif Hardware::CPU.intel?
url "https://github.com/antonio-orionus/url-sanitize/releases/download/v#{version}/url-sanitize-x86_64-apple-darwin.tar.gz"
sha256 "d6ecdef03651f0d11f2121ba278c8a5d6ba08595b180dd716a6bcc31a1e39dbf"
else
odie "unsupported macOS architecture"
end
elsif OS.linux?
if Hardware::CPU.arm?
url "https://github.com/antonio-orionus/url-sanitize/releases/download/v#{version}/url-sanitize-aarch64-unknown-linux-gnu.tar.gz"
sha256 "235988fda83f6be3a47125b1ffe8f4f868f1c087d218c6244493e7a444a35edd"
elsif Hardware::CPU.intel?
url "https://github.com/antonio-orionus/url-sanitize/releases/download/v#{version}/url-sanitize-x86_64-unknown-linux-gnu.tar.gz"
sha256 "38ed77f0afa9d19af0c6de1341bf54d3d34b2c481ae5a4d6e7c9d4043f51a948"
else
odie "unsupported Linux architecture"
end
else
odie "unsupported operating system"
end
def install
bin.install "url-sanitize"
end
test do
test_url = "https://example.com/article?utm_source=newsletter&id=123"
cleaned_url = "https://example.com/article?id=123"
version_output = shell_output("#{bin}/url-sanitize --version")
assert_match version.to_s, version_output
assert_match(/catalog [0-9a-f]{64}/, version_output)
assert_equal cleaned_url, pipe_output("#{bin}/url-sanitize -", "#{test_url}\n").strip
json_output = pipe_output("#{bin}/url-sanitize --json -", "#{test_url}\n")
parsed = JSON.parse(json_output)
assert_equal "cleaned", parsed["kind"]
assert_equal cleaned_url, parsed["url"]
assert_includes parsed["strippedParams"], "utm_source"
end
end