diff options
author | Jan Lehnardt <jan@apache.org> | 2017-10-31 20:29:57 +0100 |
---|---|---|
committer | Jan Lehnardt <jan@apache.org> | 2017-10-31 20:29:57 +0100 |
commit | f72587e941e3755b2145b8eacc18a75a365e0e51 (patch) | |
tree | d7d9d2e7044dd6ad85598527800914b1174c9f18 | |
parent | 3043fd8ea02ff1b47b5cb84c38b473dbc1cb1e11 (diff) | |
parent | 198b1e965a70bcc0aa8909302d63b5287a374653 (diff) | |
download | couchdb-f72587e941e3755b2145b8eacc18a75a365e0e51.tar.gz |
Merge branch 'ejson-dupes' into one-ex-ex
* ejson-dupes:
fix: html template got renamed
feat: disallow dupe keys
-rw-r--r-- | share/doc/build/Makefile.am | 2 | ||||
-rw-r--r-- | share/doc/templates/couchdb/theme.conf | 2 | ||||
-rw-r--r-- | src/ejson/ejson.erl | 20 |
3 files changed, 22 insertions, 2 deletions
diff --git a/share/doc/build/Makefile.am b/share/doc/build/Makefile.am index cb46c2105..452e1c1ea 100644 --- a/share/doc/build/Makefile.am +++ b/share/doc/build/Makefile.am @@ -170,7 +170,7 @@ html_files = \ html/_static/comment-bright.png \ html/_static/comment-close.png \ html/_static/comment.png \ - html/_static/default.css \ + html/_static/classic.css \ html/_static/doctools.js \ html/_static/down-pressed.png \ html/_static/down.png \ diff --git a/share/doc/templates/couchdb/theme.conf b/share/doc/templates/couchdb/theme.conf index 546fca0a2..6655d895b 100644 --- a/share/doc/templates/couchdb/theme.conf +++ b/share/doc/templates/couchdb/theme.conf @@ -10,4 +10,4 @@ ; specific language governing permissions and limitations under the License. [theme] -inherit = default +inherit = classic diff --git a/src/ejson/ejson.erl b/src/ejson/ejson.erl index 72bb6c157..aff5f3d41 100644 --- a/src/ejson/ejson.erl +++ b/src/ejson/ejson.erl @@ -36,6 +36,9 @@ init() -> decode(undefined) -> throw({invalid_json, undefined}); decode(IoList) -> + dedupe_objs(decode_int(IoList)). + +decode_int(IoList) -> try nif_decode(IoList) catch exit:ejson_nif_not_loaded -> @@ -161,6 +164,23 @@ make_ejson([Value | RevEvs], [Vals | RestStack] = _Stack) -> make_ejson(RevEvs, [[Value | Vals] | RestStack]). +dedupe_objs({Props}) when is_list(Props) -> + RevProps = lists:reverse(Props), + {_, NewProps} = lists:foldl(fun({Key, Val}, {Seen, PropAcc}) -> + case sets:is_element(Key, Seen) of + true -> + {Seen, PropAcc}; + false -> + {sets:add_element(Key, Seen), [{Key, Val} | PropAcc]} + end + end, {sets:new(), []}, RevProps), + {NewProps}; +dedupe_objs(Vals) when is_list(Vals) -> + lists:map(fun dedupe_objs/1, Vals); +dedupe_objs(Val) -> + Val. + + reverse_tokens(_) -> exit(ejson_nif_not_loaded). |