iilyak 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_r223995848
 
 

 ##########
 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:
   I wish we (CouchDB community) have a syntax guidelines. I agree, this 
formatting is a bit haskellish (or ocamellish). However it provides a good 
structure visually which helps when reading the code. Although it could be just 
me because I used to this formatting. Let me know if you want me to change it 
and which one you would prefer.
   
   1. operand (new line) operator (new line) operand
   ```
   re:run(Prefix, ?DBNAME_REGEX, [{capture,none}, dollar_endonly])
   ==
   match
   ```
   2. operand (new line) (extra indent) operator operand
   ```
   re:run(Prefix, ?DBNAME_REGEX, [{capture,none}, dollar_endonly])
       == match
   ```
   3. operand (new line) operator operand
   ```
   re:run(Prefix, ?DBNAME_REGEX, [{capture,none}, dollar_endonly])
   == match
   ```
   4. extract this into a function `match_regexp/1` and use it in other places 
as well.

----------------------------------------------------------------
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