1 #if !PLATFORM_UNIX || MONO
2 //------------------------------------------------------------------------------
3 // <copyright file="_UncName.cs" company="Microsoft">
4 // Copyright (c) Microsoft Corporation. All rights reserved.
6 //------------------------------------------------------------------------------
7 using System.Globalization;
11 // The class designed as to keep minimal the working set of Uri class.
12 // The idea is to stay with static helper methods and strings
13 internal class UncNameHelper {
17 internal const int MaximumInternetNameLength = 256;
19 private UncNameHelper() {
26 internal static string ParseCanonicalName(string str, int start, int end, ref bool loopback) {
27 return DomainNameHelper.ParseCanonicalName(str, start, end, ref loopback);
34 // ATTN: This class has been re-designed as to conform to XP+ UNC hostname format
35 // It is now similar to DNS name but can contain Unicode characters as well
36 // This class will be removed and replaced by IDN specification later,
37 // but for now we violate URI RFC cause we never escape Unicode characters on the wire
38 // For the same reason we never unescape UNC host names since we never accept
39 // them in escaped format.
42 // Valid UNC server name chars:
43 // a Unicode Letter (not allowed as the only in a segment)
46 // '.' 46 0x2E (only as a host domain delimiter)
50 // Assumption is the caller will check on the resulting name length
51 // Remarks: MUST NOT be used unless all input indexes are are verified and trusted.
52 internal unsafe static bool IsValid(char* name, ushort start, ref int returnedEnd, bool notImplicitFile) {
53 ushort end = (ushort) returnedEnd;
59 if (!Uri.IsWindowsFileSystem) {
60 if (!(end - start > 2 && name[start] == '\\' && name[start + 1] == '\\')) {
66 // First segment could consist of only '_' or '-' but it cannot be all digits or empty
68 bool validShortName = false;
72 if (name[i] == '/' || name[i] == '\\' || (notImplicitFile && (name[i] == ':' || name[i] == '?' || name[i] == '#')))
77 else if (name[i] == '.')
82 if (Char.IsLetter(name[i]) || name[i] == '-' || name[i] == '_')
84 validShortName = true;
86 else if (name[i] < '0' || name[i] > '9')
94 // Subsequent segments must start with a letter or a digit
99 if (name[i] == '/' || name[i] == '\\' || (notImplicitFile && (name[i] == ':' || name[i] == '?' || name[i] == '#')))
104 else if (name[i] == '.')
106 if (!validShortName || ((i-1) >= start && name[i-1] == '.'))
109 validShortName = false;
111 else if (name[i] == '-' || name[i] == '_')
116 else if (Char.IsLetter(name[i]) || (name[i] >= '0' && name[i] <= '9'))
119 validShortName = true;
125 // last segment can end with the dot
126 if (((i-1) >= start && name[i-1] == '.'))
127 validShortName = true;
132 // caller must check for (end - start <= MaximumInternetNameLength)
139 #endif // !PLATFORM_UNIX