diff --git a/lib/pigeon.rb b/lib/pigeon.rb index 9c0d108..9f1de82 100644 --- a/lib/pigeon.rb +++ b/lib/pigeon.rb @@ -266,8 +266,12 @@ module Pigeon end def self.decode_multihash(string) - # "FEED.", "FILE.", "USER." etc.. - return b32_decode(string[5..]) + case string[0..4] + when BLOB_SIGIL, MESSAGE_SIGIL, IDENTITY_SIGIL + return b32_decode(string[5..]) + else + return b32_decode(string) + end end end end diff --git a/lib/pigeon/lexer.rb b/lib/pigeon/lexer.rb index 6fe1dbc..a48a4bc 100644 --- a/lib/pigeon/lexer.rb +++ b/lib/pigeon/lexer.rb @@ -56,14 +56,14 @@ module Pigeon attr_reader :bundle_string, :scanner, :tokens # TODO: Change all the `{40,90}` values in ::Lexer to real values # TODO: Create regexes using string and Regexp.new() for cleaner regexes. + ALPHANUMERICISH = /[a-zA-Z0-9_\-=\.]{1,90}/ NUMERIC = /\d{1,7}/ NULL_VALUE = /NONE/ - FEED_VALUE = /USER.{52}/ - MESG_VALUE = /TEXT.{52}/ - BLOB_VALUE = /FILE.{52}/ + FEED_VALUE = /USER\.[#{ALPHANUMERICISH}]{52}/ + MESG_VALUE = /TEXT\.[#{ALPHANUMERICISH}]{52}/ + BLOB_VALUE = /FILE\.[#{ALPHANUMERICISH}]{52}/ STRG_VALUE = /".{1,128}"/ # If you need other characters (but not spaces) submit an issue. - ALPHANUMERICISH = /[a-zA-Z0-9_\-=\.\@\&]{1,90}/ ALL_VALUES = [ FEED_VALUE, MESG_VALUE, diff --git a/spec/pigeon/lexer_spec.rb b/spec/pigeon/lexer_spec.rb index 9209bb3..6502176 100644 --- a/spec/pigeon/lexer_spec.rb +++ b/spec/pigeon/lexer_spec.rb @@ -86,7 +86,7 @@ RSpec.describe Pigeon::Lexer do expect(hash[:DEPTH]).to eq(message.depth) expect(hash[:KIND]).to eq(message.kind) expect(hash[:PREV]).to eq Pigeon::NOTHING - expect(hash[:SIGNATURE]).to eq(messagenature) + expect(hash[:SIGNATURE]).to eq(message.signature) end it "catches syntax errors" do diff --git a/spec/pigeon/message_spec.rb b/spec/pigeon/message_spec.rb index 5130984..055f079 100644 --- a/spec/pigeon/message_spec.rb +++ b/spec/pigeon/message_spec.rb @@ -52,7 +52,7 @@ RSpec.describe Pigeon::Message do "prev NONE", "", "a:\"bar\"", - "b:&CHHABX8Q9D9Q0BY2BBZ6FA7SMAFNE9GGMSDTZVZZC9TK2N9F15QG.sha256", + "b:FILE.CHHABX8Q9D9Q0BY2BBZ6FA7SMAFNE9GGMSDTZVZZC9TK2N9F15QG", "", "signature __SIGNATURE__", ].join("\n")