diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2018-08-18 23:33:38 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2018-08-18 23:33:38 -0400 |
commit | 944b2995f1bf7719cfcfb9bafe713523dbd8883f (patch) | |
tree | bc0a7f30af261f1aa109acb32e56dd8c3b0cb680 /src/StardewModdingAPI.Toolkit | |
parent | d918ceb224bd6ed8b428219ab28a436896a30b45 (diff) | |
download | SMAPI-944b2995f1bf7719cfcfb9bafe713523dbd8883f.tar.gz SMAPI-944b2995f1bf7719cfcfb9bafe713523dbd8883f.tar.bz2 SMAPI-944b2995f1bf7719cfcfb9bafe713523dbd8883f.zip |
no longer allow non-relative paths for IContentPack.Read/WriteJsonFile (#468)
Diffstat (limited to 'src/StardewModdingAPI.Toolkit')
-rw-r--r-- | src/StardewModdingAPI.Toolkit/Utilities/PathUtilities.cs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/StardewModdingAPI.Toolkit/Utilities/PathUtilities.cs b/src/StardewModdingAPI.Toolkit/Utilities/PathUtilities.cs index b959f9b5..79748c25 100644 --- a/src/StardewModdingAPI.Toolkit/Utilities/PathUtilities.cs +++ b/src/StardewModdingAPI.Toolkit/Utilities/PathUtilities.cs @@ -63,6 +63,18 @@ namespace StardewModdingAPI.Toolkit.Utilities return relative; } + /// <summary>Get whether a path is relative and doesn't try to climb out of its containing folder (e.g. doesn't contain <c>../</c>).</summary> + /// <param name="path">The path to check.</param> + public static bool IsSafeRelativePath(string path) + { + if (string.IsNullOrWhiteSpace(path)) + return true; + + return + !Path.IsPathRooted(path) + && PathUtilities.GetSegments(path).All(segment => segment.Trim() != ".."); + } + /// <summary>Get whether a string is a valid 'slug', containing only basic characters that are safe in all contexts (e.g. filenames, URLs, etc).</summary> /// <param name="str">The string to check.</param> public static bool IsSlug(string str) |