浏览代码

trim trailing slashes from path substitutions

Luke Pulverenti 11 年之前
父节点
当前提交
57c92fa948
共有 1 个文件被更改,包括 26 次插入0 次删除
  1. 26 0
      MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs

+ 26 - 0
MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs

@@ -96,10 +96,36 @@ namespace MediaBrowser.Server.Implementations.Configuration
 
             ValidateItemByNamePath(newConfig);
             ValidateTranscodingTempPath(newConfig);
+            ValidatePathSubstitutions(newConfig);
 
             base.ReplaceConfiguration(newConfiguration);
         }
 
+        private void ValidatePathSubstitutions(ServerConfiguration newConfig)
+        {
+            foreach (var map in newConfig.PathSubstitutions)
+            {
+                if (string.IsNullOrWhiteSpace(map.From) || string.IsNullOrWhiteSpace(map.To))
+                {
+                    throw new ArgumentException("Invalid path substitution");
+                }
+
+                if (!map.From.EndsWith(":\\") && !map.From.EndsWith(":/"))
+                {
+                    map.From = map.From.TrimEnd('/').TrimEnd('\\');
+                }
+                if (!map.To.EndsWith(":\\") && !map.To.EndsWith(":/"))
+                {
+                    map.To = map.To.TrimEnd('/').TrimEnd('\\');
+                }
+
+                if (string.IsNullOrWhiteSpace(map.From) || string.IsNullOrWhiteSpace(map.To))
+                {
+                    throw new ArgumentException("Invalid path substitution");
+                }
+            }
+        }
+
         /// <summary>
         /// Replaces the item by name path.
         /// </summary>