Skip to content

Commit

Permalink
Enables support of unicode characters in namespaces. Issue #80
Browse files Browse the repository at this point in the history
  • Loading branch information
3F committed May 22, 2019
1 parent d5c7369 commit f4e03c4
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
4 changes: 2 additions & 2 deletions NSBin/Rmod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ public static bool IsValidNS(string name)
return true;
}

return Regex.IsMatch(name, "^[a-z_][a-z_0-9.]*$", RegexOptions.IgnoreCase)
&& !Regex.IsMatch(name, @"(?:\.(\s*\.)+|\.\s*$)"); // left. ... .right.
return Regex.IsMatch(name, @"^[^0-9\W][.\w]*$")
&& !Regex.IsMatch(name, @"(?:\.(\s*\.)+|\.\s*$)"); // left. ... .right.
}

public void setNamespace(string name, bool viaCecil, bool preparing)
Expand Down
39 changes: 34 additions & 5 deletions NSBinTest/DDNSTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,47 @@ public class DDNSTest
public void nsTest1()
{
Assert.AreEqual(true, DDNS.IsValidNS("net.r_eg.DllExport"));
Assert.AreEqual(false, DDNS.IsValidNS("net.r_eg..DllExport"));
Assert.AreEqual(true, DDNS.IsValidNS(" "));
Assert.AreEqual(true, DDNS.IsValidNS(" "));
Assert.AreEqual(true, DDNS.IsValidNS(null));
Assert.AreEqual(true, DDNS.IsValidNS(String.Empty));
}

[TestMethod]
public void nsTest2()
{
Assert.AreEqual(false, DDNS.IsValidNS("net.r-eg.DllExport"));
Assert.AreEqual(false, DDNS.IsValidNS("net. r_eg . DllExport"));
Assert.AreEqual(false, DDNS.IsValidNS("net.r_eg.DllExport."));
Assert.AreEqual(false, DDNS.IsValidNS("0net.r_eg.DllExport"));
Assert.AreEqual(false, DDNS.IsValidNS("1net.r_eg.DllExport"));

Assert.AreEqual(false, DDNS.IsValidNS("net.r_eg..DllExport"));
Assert.AreEqual(false, DDNS.IsValidNS(".net.r_eg.DllExport"));

Assert.AreEqual(true, DDNS.IsValidNS(" "));
Assert.AreEqual(true, DDNS.IsValidNS(null));
Assert.AreEqual(true, DDNS.IsValidNS(String.Empty));
Assert.AreEqual(true, DDNS.IsValidNS("_net.r_eg.DllExport"));
}

[TestMethod]
public void nsTest3()
{
// https://github.com/3F/DllExport/issues/61#issuecomment-352804273

Assert.AreEqual(true, DDNS.IsValidNS("あいうえおかきくけこ"));
Assert.AreEqual(true, DDNS.IsValidNS("中文解决方案名称"));
Assert.AreEqual(true, DDNS.IsValidNS("あいうえおかきくけこ.DllExport"));
Assert.AreEqual(true, DDNS.IsValidNS("中文解决方案名称.DllExport"));

Assert.AreEqual(true, DDNS.IsValidNS("Проверка"));
Assert.AreEqual(true, DDNS.IsValidNS("Проверка.DllExport"));

Assert.AreEqual(false, DDNS.IsValidNS("0あいうえおかきくけこ"));
Assert.AreEqual(false, DDNS.IsValidNS("0中文解决方案名称"));
Assert.AreEqual(false, DDNS.IsValidNS("0あいうえおかきくけこ.DllExport"));
Assert.AreEqual(false, DDNS.IsValidNS("0中文解决方案名称.DllExport"));

Assert.AreEqual(false, DDNS.IsValidNS("0Проверка"));
Assert.AreEqual(false, DDNS.IsValidNS("0Проверка.DllExport"));
}

}
}

0 comments on commit f4e03c4

Please sign in to comment.