File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # 0.13.1
2+ - Make Jsonpatch faster by (un)escaping conditional
3+
14# 0.13.0
25- Allow usage of atoms for keys via `keys` option
36
Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ The package can be installed by adding `jsonpatch` to your list of dependencies
3232``` elixir
3333def deps do
3434 [
35- {:jsonpatch , " ~> 0.12 .1" }
35+ {:jsonpatch , " ~> 0.13 .1" }
3636 ]
3737end
3838```
Original file line number Diff line number Diff line change @@ -216,14 +216,21 @@ defmodule Jsonpatch do
216216 Map . get ( source , key )
217217 end
218218
219- # Escape `/` to `~1 and `~` to `~`.
219+ # Escape `/` to `~1 and `~` to `~0 `.
220220 defp escape ( subpath ) when is_bitstring ( subpath ) do
221221 subpath
222- |> String . replace ( "~" , "~0" )
223- |> String . replace ( "/" , "~1" )
222+ |> do_escape ( "~" , "~0" )
223+ |> do_escape ( "/" , "~1" )
224224 end
225225
226226 defp escape ( subpath ) do
227227 subpath
228228 end
229+
230+ defp do_escape ( subpath , pattern , replacement ) do
231+ case String . contains? ( subpath , pattern ) do
232+ true -> String . replace ( subpath , pattern , replacement )
233+ false -> subpath
234+ end
235+ end
229236end
Original file line number Diff line number Diff line change @@ -75,8 +75,8 @@ defmodule Jsonpatch.PathUtil do
7575 """
7676 def unescape ( fragment ) when is_bitstring ( fragment ) do
7777 fragment
78- |> String . replace ( "~1" , "/" )
79- |> String . replace ( "~0" , "~" )
78+ |> do_unescape ( "~1" , "/" )
79+ |> do_unescape ( "~0" , "~" )
8080 end
8181
8282 def unescape ( fragment ) do
@@ -194,4 +194,15 @@ defmodule Jsonpatch.PathUtil do
194194 defp is_number? ( _term ) do
195195 false
196196 end
197+
198+ defp do_unescape ( fragment , pattern , replacement ) when is_binary ( fragment ) do
199+ case String . contains? ( fragment , pattern ) do
200+ true -> String . replace ( fragment , pattern , replacement )
201+ false -> fragment
202+ end
203+ end
204+
205+ defp do_unescape ( fragment , _pattern , _replacement ) do
206+ fragment
207+ end
197208end
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ defmodule Jsonpatch.MixProject do
66 app: :jsonpatch ,
77 name: "Jsonpatch" ,
88 description: "Implementation of RFC 6902 in pure Elixir" ,
9- version: "0.13.0 " ,
9+ version: "0.13.1 " ,
1010 elixir: "~> 1.10" ,
1111 start_permanent: Mix . env ( ) == :prod ,
1212 deps: deps ( ) ,
You can’t perform that action at this time.
0 commit comments