eiri commented on a change in pull request #1647: Validate database prefix 
against DBNAME_REGEX for system dbs
URL: https://github.com/apache/couchdb/pull/1647#discussion_r224052016
 
 

 ##########
 File path: src/couch/src/couch_db.erl
 ##########
 @@ -1738,8 +1738,16 @@ validate_dbname_int(DbName, Normalized) when 
is_binary(DbName) ->
 is_systemdb(DbName) when is_list(DbName) ->
     is_systemdb(?l2b(DbName));
 is_systemdb(DbName) when is_binary(DbName) ->
-    lists:member(dbname_suffix(DbName), ?SYSTEM_DATABASES).
-
+    Normalized = normalize_dbname(DbName),
+    Suffix = filename:basename(Normalized),
+    case {filename:dirname(Normalized), lists:member(Suffix, 
?SYSTEM_DATABASES)} of
+        {<<".">>, Result} -> Result;
+        {Prefix, false} -> false;
+        {Prefix, true} ->
+            re:run(Prefix, ?DBNAME_REGEX, [{capture,none}, dollar_endonly])
+            ==
+            match
 
 Review comment:
   personally I'd split it i two lines
   ```
   ReOpts =  [{capture,none}, dollar_endonly]
   re:run(Prefix, ?DBNAME_REGEX, ReOpts) == match
   ```
   as it is right now looks more markupish than haskellish to me.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to