diff options
author | Matthias Radestock <matthias@rabbitmq.com> | 2011-11-23 00:37:47 +0000 |
---|---|---|
committer | Matthias Radestock <matthias@rabbitmq.com> | 2011-11-23 00:37:47 +0000 |
commit | fbaadff35c44fe24dc330c3b568281caf63596c6 (patch) | |
tree | be7135d29d85fa80a15b6c9284f81550bb40423b | |
parent | 46da2f463944758c4befbe3577fdea6348954db9 (diff) | |
download | rabbitmq-server-bug24467.tar.gz |
base64url-encode for string guid generationbug24467
this works well for AMQP (with its restrictions on queue name
characters) but also when used as part of filenames, urls, etc
-rw-r--r-- | src/rabbit_guid.erl | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/rabbit_guid.erl b/src/rabbit_guid.erl index 523af749..2d0f5014 100644 --- a/src/rabbit_guid.erl +++ b/src/rabbit_guid.erl @@ -89,8 +89,15 @@ guid() -> erlang:md5(term_to_binary(G)). %% generate a readable string representation of a GUID. +%% +%% employs base64url encoding, which is safer in more contexts than +%% plain base64. string_guid(Prefix) -> - Prefix ++ "-" ++ base64:encode_to_string(guid()). + Prefix ++ "-" ++ lists:foldl(fun ($\+, Acc) -> [$\- | Acc]; + ($\/, Acc) -> [$\_ | Acc]; + ($\=, Acc) -> Acc; + (Chr, Acc) -> [Chr | Acc] + end, [], base64:encode_to_string(guid())). binstring_guid(Prefix) -> list_to_binary(string_guid(Prefix)). |