* Called to create a short code for the short link.
*/
function makeShortCode(lat, lon, zoom) {
- char_array = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_@";
+ char_array = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_~";
var x = Math.round((lon + 180.0) * ((1 << 30) / 90.0));
var y = Math.round((lat + 90.0) * ((1 << 30) / 45.0));
// JavaScript only has to keep 32 bits of bitwise operators, so this has to be
match '/forgot-password.html' => 'user#lost_password'
# permalink
- match '/go/:code' => 'site#permalink', :code => /[a-zA-Z0-9_@]+[=-]*/
+ match '/go/:code' => 'site#permalink', :code => /[a-zA-Z0-9_@~]+[=-]*/
# traces
match '/user/:display_name/traces/tag/:tag/page/:page' => 'trace#list'
# array of 64 chars to encode 6 bits. this is almost like base64 encoding, but
# the symbolic chars are different, as base64's + and / aren't very
# URL-friendly.
- ARRAY = ('A'..'Z').to_a + ('a'..'z').to_a + ('0'..'9').to_a + ['_','@']
+ ARRAY = ('A'..'Z').to_a + ('a'..'z').to_a + ('0'..'9').to_a + ['_','~']
##
# Given a string encoding a location, returns the [lon, lat, z] tuple of that
z = 0
z_offset = 0
+ # keep support for old shortlinks which use the @ character, now
+ # replaced by the ~ character because twitter is horribly broken
+ # and we can't have that.
+ str.gsub!("@","~")
+
str.each_char do |c|
t = ARRAY.index c
if t.nil?
assert max_distance > distance, "Maximum expected error exceeded: #{max_distance} <= #{distance} for (#{lat}, #{lon}, #{zoom})."
end
end
+
+ ##
+ # test that links are backwards-compatible, so any old links with
+ # the deprecated @ characters in them still work properly.
+ def test_deprecated_at_sign
+ cases = [["~v2juONc--", "@v2juONc--"],
+ ["as3I3GpG~-", "as3I3GpG@-"],
+ ["D~hV--", "D@hV--"],
+ ["CO0O~m8--", "CO0O@m8--"]]
+
+ cases.each do |new_code, old_code|
+ assert_equal ShortLink.decode(old_code), ShortLink.decode(new_code),
+ "old (#{old_code}) and new (#{new_code}) should decode to the same location."
+ end
+ end
end