Sha256: c0211f8732a9567e90fd82a36585829558f9ca0c414e54b5a2860ab8dcc3b93f
Contents?: true
Size: 688 Bytes
Versions: 2
Compression:
Stored size: 688 Bytes
Contents
require "uri" module Blobby # Defines the keys we allow for use in BLOB-store implementations. # # Basically, we allow anything that would be a valid URI "path" component. # module KeyConstraint extend self BAD_PATTERNS = [ %r{\A\Z}, # blank %r{\A/}, # leading slash %r{/\Z}, # trailing slash %r{//+}, # multiple slashes %r{:} # colon ].freeze def allows?(key) BAD_PATTERNS.none? { |pattern| pattern =~ key } && URI.parse(key).path == key rescue URI::InvalidURIError false end def must_allow!(key) fail ArgumentError, "invalid key: #{key.inspect}" unless allows?(key) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
blobby-1.0.1 | lib/blobby/key_constraint.rb |
blobby-1.0.0 | lib/blobby/key_constraint.rb |