binxtils 0.5.2 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8af9c778119b7f329d28122fcdaf2957914abe72ee7b43fde8a5b5e25a0e6294
4
- data.tar.gz: 9573e86af8de64e62d98cb64c47c59040897fe3202d2b1167b740404301d270f
3
+ metadata.gz: 58786a3391a102bc9a6e08a9420088cf9796ae49f425af65bd40504bb350ea37
4
+ data.tar.gz: decb330bdb3ac5b78b24fdff8fa8431331a8933b4b5e6c06957850e7d5910de4
5
5
  SHA512:
6
- metadata.gz: 3439600aa1a4add439671f2dcee1434f4627d9968645b05634f734d643d007fbec2a5eb40b93192b457edc0a14bcbab3b4ed4e64a05d5f560a0f1df924fe2fe0
7
- data.tar.gz: 6e77b0e688d8c58b5d9bdc20d636ad743f95bd4b7218c49b97ad86c8011010aa8d116414ecd1206f6e2d6ecb855c7587bbbca46938485c820a004aba0edcd7e9
6
+ metadata.gz: 8ebdeccb552c059b0f4d6951cf6e5305656c97a0d5949d8536fa920e96bce5b211ced41f9eb0252d4420973c3ef853286a2be01ae25ed0a3e63c55feac03d2cc
7
+ data.tar.gz: 309384e08b2afb921202bd92fede339d559f29857a58b3ab23ed667652182a87252a4424c708d57e74345f6a4f523eb26426ce3c51cacacaaf835eb6efa7cb5f
data/README.md CHANGED
@@ -9,6 +9,7 @@ gem "binxtils"
9
9
  ## Modules
10
10
 
11
11
  - **Binxtils::InputNormalizer** - Sanitize and normalize user input strings
12
+ - **Binxtils::Secure** - Constant-time comparison of a value against an expected secret
12
13
  - **Binxtils::TimeParser** - Parse fuzzy time/date strings into `Time` objects
13
14
  - **Binxtils::TimeZoneParser** - Parse and resolve time zone strings
14
15
 
@@ -20,6 +21,7 @@ These modules use [Functionable](https://github.com/sethherr/functionable) and a
20
21
  Binxtils::TimeParser.parse("next thursday")
21
22
  Binxtils::InputNormalizer.string(" Some Input ")
22
23
  Binxtils::TimeZoneParser.parse("Eastern Time")
24
+ Binxtils::Secure.compare?(params[:token], ENV["WEBHOOK_TOKEN"])
23
25
  ```
24
26
 
25
27
  ### Rails concerns
@@ -59,9 +61,18 @@ end
59
61
 
60
62
  ## npm package
61
63
 
62
- This repo also publishes `@bikeindex/time-localizer`, an npm package for localizing time elements in the browser. Luxon is bundled into the published package, so consumers don't need to install it separately.
64
+ This repo also publishes `@bikeindex/time-localizer`, an npm package for localizing time elements in the browser. It ships two builds of the same source:
63
65
 
64
- To publish a new version: update the version in `package.json`, then run `npm publish` from the repo root (requires npm login with access to the `@bikeindex` scope). The `prepublishOnly` script automatically builds `dist/index.js` before publishing.
66
+ | Build | Luxon | Use when |
67
+ | --- | --- | --- |
68
+ | `dist/index.js` (default) | external — install it yourself | You have a bundler. Luxon stays deduped with your own copy, so `Settings.defaultLocale`, `Settings.now` etc. apply to both. |
69
+ | `dist/index.bundle.js` | bundled in | You have no bundler (e.g. importmap-rails). One request, nothing to resolve. |
70
+
71
+ Import the default as `@bikeindex/time-localizer` and the standalone as `@bikeindex/time-localizer/bundle`, or reference either file path directly over a CDN.
72
+
73
+ Don't use the bundled build alongside your own Luxon: you'd ship two copies, and because Luxon's `Settings` are module-scoped, your global config would silently apply to only one of them.
74
+
75
+ To publish a new version: update the version in `package.json`, then run `npm publish` from the repo root (requires npm login with access to the `@bikeindex` scope). The `prepublishOnly` script builds both artifacts before publishing.
65
76
 
66
77
  ## Releasing
67
78
 
@@ -20,6 +20,11 @@ module Binxtils
20
20
  val.to_s.present?
21
21
  end
22
22
 
23
+ def regex_escape(val)
24
+ # Lazy hack, good enough for current purposes. Improve if required!
25
+ string(val)&.gsub(/\W/, ".")
26
+ end
27
+
23
28
  def sanitize(str = nil)
24
29
  Rails::Html::Sanitizer.full_sanitizer.new.sanitize(str.to_s, encode_special_chars: true)
25
30
  .strip
@@ -27,9 +32,14 @@ module Binxtils
27
32
  .gsub(/\s+/, " ") # remove extra whitespace
28
33
  end
29
34
 
30
- def regex_escape(val)
31
- # Lazy hack, good enough for current purposes. Improve if required!
32
- string(val)&.gsub(/\W/, ".")
35
+ # Plain text, so unlike sanitize: every entity is decoded and angle brackets stay literal
36
+ def plain_text(value = nil)
37
+ normalize_whitespace(CGI.unescapeHTML(Rails::Html::Sanitizer.full_sanitizer.new.sanitize(value.to_s)))
38
+ end
39
+
40
+ # An HTML email's "blank" lines are often a  , which String#strip doesn't count as whitespace
41
+ def normalize_whitespace(value = nil)
42
+ value.to_s.tr(" ", " ").lines.map(&:strip).join("\n").gsub(/\n{3,}/, "\n\n").strip
33
43
  end
34
44
  end
35
45
  end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Binxtils
4
+ module Secure
5
+ extend Functionable
6
+
7
+ def compare?(value, expected)
8
+ expected.present? && ActiveSupport::SecurityUtils.secure_compare(value.to_s, expected.to_s)
9
+ end
10
+ end
11
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Binxtils
4
- VERSION = "0.5.2"
4
+ VERSION = "0.7.0"
5
5
  end
data/lib/binxtils.rb CHANGED
@@ -4,10 +4,12 @@ require "functionable"
4
4
  require "active_support"
5
5
  require "active_support/core_ext"
6
6
  require "active_record"
7
+ require "active_support/security_utils"
7
8
  require "loofah"
8
9
  require "rails-html-sanitizer"
9
10
 
10
11
  require_relative "binxtils/input_normalizer"
12
+ require_relative "binxtils/secure"
11
13
  require_relative "binxtils/time_zone_parser"
12
14
  require_relative "binxtils/time_parser"
13
15
  require "binxtils/set_period"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: binxtils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bike Index
@@ -81,6 +81,7 @@ files:
81
81
  - lib/binxtils.rb
82
82
  - lib/binxtils/engine.rb
83
83
  - lib/binxtils/input_normalizer.rb
84
+ - lib/binxtils/secure.rb
84
85
  - lib/binxtils/time_parser.rb
85
86
  - lib/binxtils/time_zone_parser.rb
86
87
  - lib/binxtils/version.rb