< Summary

Information
Class: Renci.SshNet.RemotePathDoubleQuoteTransformation
Assembly: Renci.SshNet
File(s): \home\appveyor\projects\ssh-net\src\Renci.SshNet\RemotePathDoubleQuoteTransformation.cs
Line coverage
100%
Covered lines: 17
Uncovered lines: 0
Coverable lines: 17
Total lines: 77
Line coverage: 100%
Branch coverage
100%
Covered branches: 6
Total branches: 6
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
Transform(...)100%6100%

File(s)

\home\appveyor\projects\ssh-net\src\Renci.SshNet\RemotePathDoubleQuoteTransformation.cs

#LineLine coverage
 1using System;
 2using System.Text;
 3
 4namespace Renci.SshNet
 5{
 6    /// <summary>
 7    /// Encloses a path in double quotes, and escapes any embedded double quote with a backslash.
 8    /// </summary>
 9    internal sealed class RemotePathDoubleQuoteTransformation : IRemotePathTransformation
 10    {
 11        /// <summary>
 12        /// Encloses a path in double quotes, and escapes any embedded double quote with a backslash.
 13        /// </summary>
 14        /// <param name="path">The path to transform.</param>
 15        /// <returns>
 16        /// The transformed path.
 17        /// </returns>
 18        /// <exception cref="ArgumentNullException"><paramref name="path"/> is <see langword="null"/>.</exception>
 19        /// <example>
 20        /// <list type="table">
 21        ///   <listheader>
 22        ///     <term>Original</term>
 23        ///     <term>Transformed</term>
 24        ///   </listheader>
 25        ///   <item>
 26        ///     <term>/var/log/auth.log</term>
 27        ///     <term>&quot;/var/log/auth.log&quot;</term>
 28        ///   </item>
 29        ///   <item>
 30        ///     <term>/var/mp3/Guns N' Roses</term>
 31        ///     <term>&quot;/var/mp3/Guns N' Roses&quot;</term>
 32        ///   </item>
 33        ///   <item>
 34        ///     <term>/var/garbage!/temp</term>
 35        ///     <term>&quot;/var/garbage!/temp&quot;</term>
 36        ///   </item>
 37        ///   <item>
 38        ///     <term>/var/would be 'kewl'!/not?</term>
 39        ///     <term>&quot;/var/would be 'kewl'!, not?&quot;</term>
 40        ///   </item>
 41        ///   <item>
 42        ///     <term></term>
 43        ///     <term>&quot;&quot;</term>
 44        ///   </item>
 45        ///   <item>
 46        ///     <term>Hello &quot;World&quot;</term>
 47        ///     <term>&quot;Hello \&quot;World&quot;</term>
 48        ///   </item>
 49        /// </list>
 50        /// </example>
 51        public string Transform(string path)
 67952        {
 67953            if (path is null)
 354            {
 355                throw new ArgumentNullException(nameof(path));
 56            }
 57
 67658            var transformed = new StringBuilder(path.Length);
 59
 67660            _ = transformed.Append('"');
 61
 1470662            foreach (var c in path)
 633963            {
 633964                if (c == '"')
 2165                {
 2166                    _ = transformed.Append('\\');
 2167                }
 68
 633969                _ = transformed.Append(c);
 633970            }
 71
 67672            _ = transformed.Append('"');
 73
 67674            return transformed.ToString();
 67675        }
 76    }
 77}

Methods/Properties

Transform(System.String)