diff --git a/lib/jsonpatch/utils.ex b/lib/jsonpatch/utils.ex index ca61f1c..a6455a0 100644 --- a/lib/jsonpatch/utils.ex +++ b/lib/jsonpatch/utils.ex @@ -192,8 +192,8 @@ defmodule Jsonpatch.Utils do @spec unescape(fragment :: String.t() | integer()) :: String.t() def unescape(fragment) when is_binary(fragment) do fragment - |> String.replace("~0", "~") |> String.replace("~1", "/") + |> String.replace("~0", "~") end @doc """ diff --git a/test/jsonpatch/utils_test.exs b/test/jsonpatch/utils_test.exs index 893eebc..767d540 100644 --- a/test/jsonpatch/utils_test.exs +++ b/test/jsonpatch/utils_test.exs @@ -16,5 +16,6 @@ defmodule Jsonpatch.UtilsTest do assert "unescape~me" = Utils.unescape("unescape~0me") assert "unescape/me" = Utils.unescape("unescape~1me") assert "unescape~me/" = Utils.unescape("unescape~0me~1") + assert "unescape~1me" = Utils.unescape("unescape~01me") end end diff --git a/test/jsonpatch_test.exs b/test/jsonpatch_test.exs index f4d60e4..daf1c61 100644 --- a/test/jsonpatch_test.exs +++ b/test/jsonpatch_test.exs @@ -103,6 +103,13 @@ defmodule JsonpatchTest do assert_diff_apply(source, destination) end + test "Create diff with a key that looks like an escape sequence" do + source = %{"~1" => "a", "~0" => "b"} + destination = %{"~1" => "c", "~01" => "d"} + + assert_diff_apply(source, destination) + end + test "Create diff with nested map with correct Add/Remove order" do source = %{"a" => [%{"b" => []}]} destination = %{"a" => [%{"b" => [%{"c" => 1}, %{"d" => 2}]}]}