summaryrefslogtreecommitdiff
path: root/src/rabbit_guid.erl
diff options
context:
space:
mode:
authorMatthias Radestock <matthias@rabbitmq.com>2011-11-23 00:37:47 +0000
committerMatthias Radestock <matthias@rabbitmq.com>2011-11-23 00:37:47 +0000
commitfbaadff35c44fe24dc330c3b568281caf63596c6 (patch)
treebe7135d29d85fa80a15b6c9284f81550bb40423b /src/rabbit_guid.erl
parent46da2f463944758c4befbe3577fdea6348954db9 (diff)
downloadrabbitmq-server-fbaadff35c44fe24dc330c3b568281caf63596c6.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
Diffstat (limited to 'src/rabbit_guid.erl')
-rw-r--r--src/rabbit_guid.erl9
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)).