From bcb14eaa6176ecfd420f6dbc554714474af55798 Mon Sep 17 00:00:00 2001 From: Doug Bell Date: Thu, 13 Jan 2011 15:00:50 -0600 Subject: [PATCH] remove MIME::Base64::URLSafe as they do it reversely --- lib/WebGUI/GUID.pm | 12 ++++++++---- t/Session/Id.t | 1 + 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/WebGUI/GUID.pm b/lib/WebGUI/GUID.pm index 845a3de94..2c2022dde 100644 --- a/lib/WebGUI/GUID.pm +++ b/lib/WebGUI/GUID.pm @@ -17,7 +17,7 @@ package WebGUI::GUID; use strict; use WebGUI::BestPractices; -use MIME::Base64::URLSafe; +use MIME::Base64; use UUID::Tiny; my $idValidator = qr/^[A-Za-z0-9_-]{22}$/; @@ -58,7 +58,8 @@ sub fromHex { shift; my $hexId = shift; my $binId = pack( 'H2' x 16, unpack( 'A2' x 16, $hexId ) ); - my $id = substr( urlsafe_b64encode($binId), 0, 22 ); + my $id = substr( encode_base64($binId), 0, 22 ); + $id =~ tr{+/}{_-}; return $id; } @@ -85,7 +86,9 @@ This function generates a global unique id. sub generate { shift; - return urlsafe_b64encode( create_UUID( UUID_V4 ) ); + my $id = substr( encode_base64( create_UUID( UUID_V4 ) ), 0, 22 ); + $id =~ tr{+/}{_-}; + return $id; } #------------------------------------------------------------------- @@ -103,8 +106,9 @@ guid to convert to hex value. sub toHex { shift; my $id = shift; + $id =~ tr{_-}{+/}; $id .= 'AA'; - my $bin_id = urlsafe_b64decode($id); + my $bin_id = decode_base64($id); my $hex_id = unpack("H*", $bin_id); $hex_id =~ s/0{3,4}$//; return $hex_id; diff --git a/t/Session/Id.t b/t/Session/Id.t index 3d96d7924..914494c1d 100644 --- a/t/Session/Id.t +++ b/t/Session/Id.t @@ -81,6 +81,7 @@ foreach my $testSet (@testSets) { is($session->id->toHex('wjabZsKOb7kBBSiO3bQwzA'), 'c2369b66c28e6fb90105288eddb430cc', 'toHex works'); is($session->id->fromHex('c2369b66c28e6fb90105288eddb430cc'), 'wjabZsKOb7kBBSiO3bQwzA', 'fromHex works'); +is( $session->id->toHex('EhTwB4FAnLZPn-ftde39aA'), '1214f00781409cb64f9ff7ed75edfd68', 'toHex with -' ); my $re = $session->id->getValidator; is( ref $re, 'Regexp', 'getValidator returns a regexp object');