A simple Ruby server using Sinatra that serves Bluesky custom feeds

verify feed key with regexp

+5 -3
+5 -3
lib/blue_factory/modules/feeds.rb
··· 12 12 target.instance_variable_set('@feeds', {}) 13 13 end 14 14 15 + RKEY_REGEXP = /\A[A-Za-z0-9\.\-_:~]+\z/ 16 + 15 17 # 16 18 # Registers a feed handler for a given rkey. The full AT URI of the feed generator, which is 17 19 # listed in `describeFeedGenerator` and expected in the `feed` parameter to `getFeedSkeleton` ··· 68 70 private 69 71 70 72 def validate_key(key) 71 - raise InvalidKeyError, "Key must be a string" unless key.is_a?(String) 73 + raise InvalidKeyError, "Key must be a string (got: #{key.inspect})" unless key.is_a?(String) 72 74 raise InvalidKeyError, "Key must not be empty" if key == '' 73 - raise InvalidKeyError, "Key must not contain a slash" if key.include?('/') 74 - raise InvalidKeyError, "Key must not be longer than 15 characters" if key.length > 15 75 + raise InvalidKeyError, "Key must not be longer than 15 characters (got: #{key.inspect})" if key.length > 15 76 + raise InvalidKeyError, "Key #{key.inspect} contains invalid characters" if key !~ RKEY_REGEXP 75 77 end 76 78 77 79 private_class_method :extended