couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Anderson <jch...@apache.org>
Subject Re: Apache Maven/Maven repo (Re: Dependencies in SVN)
Date Tue, 11 Aug 2009 06:36:07 GMT
On Mon, Aug 10, 2009 at 10:36 PM, Paul Davis<paul.joseph.davis@gmail.com> wrote:
>>
>> I do not think that the question posed on legal-discuss really describes the
>> situation since the dependencies are not unmodified copies of upstream
>> release but are abridged and in the case of mochiweb functionally modified.
>>
>
> Not sure what you mean by abridged. Is that because we move files
> around to fit our build system instead of having identical copies and
> then scripting a build on each dep independently?
>
> For posterity, our current functional modification to mochiweb is this
> diff. I was actually a bit curious to look at the differences. Notice
> that I reverted my SVN checkout of mochiweb back to r97 which is what
> we have in trunk. The one big patch that looks to be different is the
> utf-8 patch that was applied to our version. In MochiWeb revisions r98
> and r99 there was a slightly different patch applied upstream. I'm not
> entirely certain on the difference, but my guess is that resolving the
> disparity would be figuring out which version is better and going with
> that.
>
> The actual functional differences of import are still the {object,
> PROPLIST} vs {PROPLIST} edit that we have in our version. After
> talking with a few people it sounds like we just never submitted a
> patch after finishing that. So that'll be on the agenda to get
> upstream if possible. In the worst case, keeping that as a local patch
> we apply after copying files from SVN wouldn't be an issue because its
> quite a small patch.
>
> HTH,
> Paul Davis
>

I think I mentioned wanting to fix this a few weeks ago, before all
the scrutiny. To me it makes sense to wait on changing mochijson until
after we've released 0.10. If we disrupt the JSON conversion, it's
better to do it while we've got all of 0.11 ahead of us, to give us
time to iron out any subtleties. Maybe I'm being too conservative.

Now is a good time to send our {object, proplist()} -> {proplist()}
patch upstream. I think we should wait for them to apply it, and then
switch to their library. As for the UTF-8 stuff, I suppose it's worth
showing them, too, but I don't think we're too attached to it.

On the other hand, if we can get the native JSON parser building
reliably, maybe we would just go with that instead.

Chris




> diff -wur mochiweb/src/mochifmt.erl cmw/mochifmt.erl
> --- mochiweb/src/mochifmt.erl   2009-08-11 00:22:33.000000000 -0400
> +++ cmw/mochifmt.erl    2009-08-11 00:23:31.000000000 -0400
> @@ -297,7 +297,7 @@
>  convert2(Arg, #conversion{ctype=upper_hex}) ->
>     erlang:integer_to_list(Arg, 16);
>  convert2(Arg, #conversion{ctype=hex}) ->
> -    string:to_lower(erlang:integer_to_list(Arg, 16));
> +    mochiweb_util:to_lower(erlang:integer_to_list(Arg, 16));
>  convert2(Arg, #conversion{ctype=char}) when Arg < 16#80 ->
>     [Arg];
>  convert2(Arg, #conversion{ctype=char}) ->
> diff -wur mochiweb/src/mochijson2.erl cmw/mochijson2.erl
> --- mochiweb/src/mochijson2.erl 2009-08-11 00:26:20.000000000 -0400
> +++ cmw/mochijson2.erl  2009-08-11 00:23:31.000000000 -0400
> @@ -70,7 +70,10 @@
>  %% @spec decode(iolist()) -> json_term()
>  %% @doc Decode the given iolist to Erlang terms.
>  decode(S) ->
> -    json_decode(S, #decoder{}).
> +    try json_decode(S, #decoder{})
> +    catch
> +        _:_ -> throw({invalid_json, S})
> +    end.
>
>  test() ->
>     test_all().
> @@ -93,18 +96,15 @@
>     <<"false">>;
>  json_encode(null, _State) ->
>     <<"null">>;
> -json_encode(I, _State) when is_integer(I) andalso I >= -2147483648
> andalso I =< 2147483647 ->
> -    %% Anything outside of 32-bit integers should be encoded as a float
> -    integer_to_list(I);
>  json_encode(I, _State) when is_integer(I) ->
> -    mochinum:digits(float(I));
> +    integer_to_list(I);
>  json_encode(F, _State) when is_float(F) ->
>     mochinum:digits(F);
>  json_encode(S, State) when is_binary(S); is_atom(S) ->
>     json_encode_string(S, State);
>  json_encode(Array, State) when is_list(Array) ->
>     json_encode_array(Array, State);
> -json_encode({struct, Props}, State) when is_list(Props) ->
> +json_encode({Props}, State) when is_list(Props) ->
>     json_encode_proplist(Props, State);
>  json_encode(Bad, #encoder{handler=null}) ->
>     exit({json_encode, {bad_term, Bad}});
> @@ -288,7 +288,7 @@
>  decode_object(B, S=#decoder{state=key}, Acc) ->
>     case tokenize(B, S) of
>         {end_object, S1} ->
> -            V = make_object({struct, lists:reverse(Acc)}, S1),
> +            V = make_object({lists:reverse(Acc)}, S1),
>             {V, S1#decoder{state=null}};
>         {{const, K}, S1} ->
>             {colon, S2} = tokenize(B, S1),
> @@ -298,7 +298,7 @@
>  decode_object(B, S=#decoder{state=comma}, Acc) ->
>     case tokenize(B, S) of
>         {end_object, S1} ->
> -            V = make_object({struct, lists:reverse(Acc)}, S1),
> +            V = make_object({lists:reverse(Acc)}, S1),
>             {V, S1#decoder{state=null}};
>         {comma, S1} ->
>             decode_object(B, S1#decoder{state=key}, Acc)
> @@ -371,11 +371,20 @@
>             tokenize_string(B, ?ADV_COL(S, 2), [$\r | Acc]);
>         <<_:O/binary, "\\t", _/binary>> ->
>             tokenize_string(B, ?ADV_COL(S, 2), [$\t | Acc]);
> -        <<_:O/binary, "\\u", C3, C2, C1, C0, _/binary>> ->
> -            %% coalesce UTF-16 surrogate pair?
> +        <<_:O/binary, "\\u", C3, C2, C1, C0, Rest/binary>> ->
>             C = erlang:list_to_integer([C3, C2, C1, C0], 16),
> +            if C > 16#D7FF, C < 16#DC00 ->
> +                %% coalesce UTF-16 surrogate pair
> +                <<"\\u", D3, D2, D1, D0, _/binary>> = Rest,
> +                D = erlang:list_to_integer([D3,D2,D1,D0], 16),
> +                [CodePoint] =
> xmerl_ucs:from_utf16be(<<C:16/big-unsigned-integer,
> +                    D:16/big-unsigned-integer>>),
> +                Acc1 = lists:reverse(xmerl_ucs:to_utf8(CodePoint), Acc),
> +                tokenize_string(B, ?ADV_COL(S, 12), Acc1);
> +            true ->
>             Acc1 = lists:reverse(xmerl_ucs:to_utf8(C), Acc),
> -            tokenize_string(B, ?ADV_COL(S, 6), Acc1);
> +                tokenize_string(B, ?ADV_COL(S, 6), Acc1)
> +            end;
>         <<_:O/binary, C, _/binary>> ->
>             tokenize_string(B, ?INC_CHAR(S, C), [C | Acc])
>     end.
> @@ -484,9 +493,9 @@
>  %% Create an object from a list of Key/Value pairs.
>
>  obj_new() ->
> -    {struct, []}.
> +    {[]}.
>
> -is_obj({struct, Props}) ->
> +is_obj({Props}) ->
>     F = fun ({K, _}) when is_binary(K) ->
>                 true;
>             (_) ->
> @@ -495,7 +504,7 @@
>     lists:all(F, Props).
>
>  obj_from_list(Props) ->
> -    Obj = {struct, Props},
> +    Obj = {Props},
>     case is_obj(Obj) of
>         true -> Obj;
>         false -> exit({json_bad_object, Obj})
> @@ -506,7 +515,7 @@
>  %% compare unequal as erlang terms, so we need to carefully recurse
>  %% through aggregates (tuples and objects).
>
> -equiv({struct, Props1}, {struct, Props2}) ->
> +equiv({Props1}, {Props2}) ->
>     equiv_object(Props1, Props2);
>  equiv(L1, L2) when is_list(L1), is_list(L2) ->
>     equiv_list(L1, L2);
> @@ -541,6 +550,7 @@
>
>  test_all() ->
>     [1199344435545.0, 1] = decode(<<"[1199344435545.0,1]">>),
> +    <<16#F0,16#9D,16#9C,16#95>> = decode([34,"\\ud835","\\udf15",34]),
>     test_one(e2j_test_vec(utf8), 1).
>
>  test_one([], _N) ->
> Only in mochiweb/src/: mochiweb.app
> diff -wur mochiweb/src/mochiweb_cookies.erl cmw/mochiweb_cookies.erl
> --- mochiweb/src/mochiweb_cookies.erl   2009-08-11 00:26:17.000000000 -0400
> +++ cmw/mochiweb_cookies.erl    2009-08-11 00:23:31.000000000 -0400
> @@ -32,7 +32,7 @@
>  %% @spec cookie(Key::string(), Value::string(), Options::[Option]) -> header()
>  %% where Option = {max_age, integer()} | {local_time, {date(), time()}}
>  %%                | {domain, string()} | {path, string()}
> -%%                | {secure, true | false}
> +%%                | {secure, true | false} | {http_only, true | false}
>  %%
>  %% @doc Generate a Set-Cookie header field tuple.
>  cookie(Key, Value, Options) ->
> @@ -83,7 +83,14 @@
>             Path ->
>                 ["; Path=", quote(Path)]
>         end,
> -    CookieParts = [Cookie, ExpiresPart, SecurePart, DomainPart, PathPart],
> +    HttpOnlyPart =
> +        case proplists:get_value(http_only, Options) of
> +            true ->
> +                "; HttpOnly";
> +            _ ->
> +                ""
> +        end,
> +    CookieParts = [Cookie, ExpiresPart, SecurePart, DomainPart,
> PathPart, HttpOnlyPart],
>     {"Set-Cookie", lists:flatten(CookieParts)}.
>
>
> diff -wur mochiweb/src/mochiweb_headers.erl cmw/mochiweb_headers.erl
> --- mochiweb/src/mochiweb_headers.erl   2009-08-11 00:22:33.000000000 -0400
> +++ cmw/mochiweb_headers.erl    2009-08-11 00:23:31.000000000 -0400
> @@ -168,7 +168,7 @@
>     V0 ++ ", " ++ V1.
>
>  normalize(K) when is_list(K) ->
> -    string:to_lower(K);
> +    mochiweb_util:to_lower(K);
>  normalize(K) when is_atom(K) ->
>     normalize(atom_to_list(K));
>  normalize(K) when is_binary(K) ->
> diff -wur mochiweb/src/mochiweb_html.erl cmw/mochiweb_html.erl
> --- mochiweb/src/mochiweb_html.erl      2009-08-11 00:26:21.000000000 -0400
> +++ cmw/mochiweb_html.erl       2009-08-11 00:23:31.000000000 -0400
> @@ -330,7 +330,7 @@
>     end.
>
>  parse_flag({start_tag, B, _, false}) ->
> -    case string:to_lower(binary_to_list(B)) of
> +    case mochiweb_util:to_lower(binary_to_list(B)) of
>         "script" ->
>             script;
>         "textarea" ->
> @@ -551,7 +551,7 @@
>  norm(Tag) when is_binary(Tag) ->
>     Tag;
>  norm(Tag) ->
> -    list_to_binary(string:to_lower(Tag)).
> +    list_to_binary(mochiweb_util:to_lower(Tag)).
>
>  test_destack() ->
>     {<<"a">>, [], []} =
> diff -wur mochiweb/src/mochiweb_multipart.erl cmw/mochiweb_multipart.erl
> --- mochiweb/src/mochiweb_multipart.erl 2009-08-11 00:22:33.000000000 -0400
> +++ cmw/mochiweb_multipart.erl  2009-08-11 00:23:31.000000000 -0400
> @@ -103,7 +103,7 @@
>  split_header(Line) ->
>     {Name, [$: | Value]} = lists:splitwith(fun (C) -> C =/= $: end,
>                                            binary_to_list(Line)),
> -    {string:to_lower(string:strip(Name)),
> +    {mochiweb_util:to_lower(string:strip(Name)),
>      mochiweb_util:parse_header(Value)}.
>
>  read_chunk(Req, Length) when Length > 0 ->
> diff -wur mochiweb/src/mochiweb_util.erl cmw/mochiweb_util.erl
> --- mochiweb/src/mochiweb_util.erl      2009-08-11 00:22:33.000000000 -0400
> +++ cmw/mochiweb_util.erl       2009-08-11 00:23:31.000000000 -0400
> @@ -12,6 +12,7 @@
>  -export([shell_quote/1, cmd/1, cmd_string/1, cmd_port/2]).
>  -export([record_to_proplist/2, record_to_proplist/3]).
>  -export([safe_relative_path/1, partition/2]).
> +-export([to_lower/1]).
>  -export([test/0]).
>
>  -define(PERCENT, 37).  % $\%
> @@ -78,7 +79,7 @@
>         [] ->
>             "";
>         _ ->
> -            string:join(lists:reverse(Acc), "/")
> +            join(lists:reverse(Acc), "/")
>     end;
>  safe_relative_path(P, Acc) ->
>     case partition(P, "/") of
> @@ -238,7 +239,7 @@
>  urlsplit_scheme([], Acc) ->
>     {"", lists:reverse(Acc)};
>  urlsplit_scheme(":" ++ Rest, Acc) ->
> -    {string:to_lower(lists:reverse(Acc)), Rest};
> +    {to_lower(lists:reverse(Acc)), Rest};
>  urlsplit_scheme([C | Rest], Acc) ->
>     urlsplit_scheme(Rest, [C | Acc]).
>
> @@ -390,11 +391,11 @@
>                         %% Skip anything with no value
>                         Acc;
>                     {Name, [$\= | Value]} ->
> -                        [{string:to_lower(string:strip(Name)),
> +                        [{to_lower(string:strip(Name)),
>                           unquote_header(string:strip(Value))} | Acc]
>                 end
>         end,
> -    {string:to_lower(Type),
> +    {to_lower(Type),
>      lists:foldr(F, [], Parts)}.
>
>  unquote_header("\"" ++ Rest) ->
> @@ -437,6 +438,20 @@
>  shell_quote([C | Rest], Acc) ->
>     shell_quote(Rest, [C | Acc]).
>
> +to_lower_char(C) when is_integer(C),  C >= $A, C =< $Z ->
> +    C + 32;
> +to_lower_char(C) when is_integer(C),  C >= 16#C1, C =< 16#D6 ->
> +    C + 32;
> +to_lower_char(C) when is_integer(C),  C >= 16#D8, C =< 16#DE ->
> +    C + 32;
> +to_lower_char(C) ->
> +    C.
> +
> +to_lower(S) when is_list(S) ->
> +    [to_lower_char(C) || C <- S];
> +to_lower(C) when is_integer(C) ->
> +    to_lower_char(C).
> +
>  test() ->
>     test_join(),
>     test_quote_plus(),
>



-- 
Chris Anderson
http://jchrisa.net
http://couch.io

Mime
View raw message