Github user kxepal commented on the pull request:

    https://github.com/apache/couchdb-couch/pull/102#issuecomment-142202867
  
    Alternative solution:
    
    ```
    diff --git a/src/couch_db.erl b/src/couch_db.erl
    index 6f767d9..877e907 100644
    --- a/src/couch_db.erl
    +++ b/src/couch_db.erl
    @@ -1514,7 +1514,10 @@ validate_dbname(DbName) when is_binary(DbName) ->
     validate_dbname_int(DbName, Normalized) when is_binary(DbName) ->
         case re:run(DbName, ?DBNAME_REGEX, [{capture,none}, dollar_endonly]) of
             match ->
    -            ok;
    +            case validate_part_lengths(DbName) of
    +                ok -> ok;
    +                error -> {error, {database_name_too_long, DbName}}
    +            end;
             nomatch ->
                 case is_systemdb(Normalized) of
                     true -> ok;
    @@ -1522,6 +1525,15 @@ validate_dbname_int(DbName, Normalized) when 
is_binary(DbName) ->
                 end
         end.
     
    +validate_part_lengths(DbName) when is_binary(DbName)->
    +  validate_part_lengths(filename:split(DbName));
    +validate_part_lengths([]) ->
    +    ok;
    +validate_part_lengths([Part | Rest]) when byte_size(Part) =< 128 ->
    +    validate_part_lengths(Rest);
    +validate_part_lengths([Part | Rest]) when byte_size(Part) > 128 ->
    +    error.
    +
    ```
    
    It makes `validate_dbname_int` looks nice:
    ```
    validate_dbname_int(DbName, Normalized) when is_binary(DbName) ->
        case re:run(DbName, ?DBNAME_REGEX, [{capture,none}, dollar_endonly]) of
            match ->
                case validate_part_lengths(DbName) of
                    ok -> ok;
                    error -> {error, {database_name_too_long, DbName}}
                end;
            nomatch ->
                case is_systemdb(Normalized) of
                    true -> ok;
                    false -> {error, {illegal_database_name, DbName}}
                end
        end.
    ```


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to