From d6015338c8fea62602e969a498b80c2a5b754909 Mon Sep 17 00:00:00 2001 From: href Date: Sat, 26 Jan 2019 16:58:23 +0100 Subject: [PATCH] Flake: support integers in from_string/1 Some previously issued stateless tokens have integer ids in them. --- lib/pleroma/flake_id.ex | 4 ++++ test/flake_id_test.exs | 1 + 2 files changed, 5 insertions(+) diff --git a/lib/pleroma/flake_id.ex b/lib/pleroma/flake_id.ex index 26399ae05..69482f69a 100644 --- a/lib/pleroma/flake_id.ex +++ b/lib/pleroma/flake_id.ex @@ -33,6 +33,10 @@ defmodule Pleroma.FlakeId do def to_string(s), do: s + def from_string(int) when is_integer(int) do + from_string(Kernel.to_string(int)) + end + for i <- [-1, 0] do def from_string(unquote(i)), do: <<0::integer-size(128)>> def from_string(unquote(Kernel.to_string(i))), do: <<0::integer-size(128)>> diff --git a/test/flake_id_test.exs b/test/flake_id_test.exs index 8e969fd1c..ca2338041 100644 --- a/test/flake_id_test.exs +++ b/test/flake_id_test.exs @@ -11,6 +11,7 @@ defmodule Pleroma.FlakeIdTest do test "from_string/1" do fake_flake = <<0::integer-size(64), 42::integer-size(64)>> assert from_string("42") == fake_flake + assert from_string(42) == fake_flake end test "zero or -1 is a null flake" do -- 2.45.2